您的位置:首页 > 编程语言 > Lua

几种语言原生开发环境构建之--Lua语言

2016-08-02 21:34 645 查看
安装目录

假设安装目录为 /home/user/soft/

lua语言安装

$ export PATH=/home/user/soft/lua:$PATH
$ cd /home/user/soft/
$ curl -R -O http://www.lua.org/ftp/lua-5.3.4.tar.gz $ tar zxf lua-5.3.4.tar.gz
$ mv lua-5.3.4 lua
$ cd lua
$ make linux install INSTALL_TOP=../
$ lua

lua包管理器安装luarocks

$ cd /home/user/soft/lua
$ export PATH=/home/user/soft/lua:$PATH
$ wget http://luarocks.org/releases/luarocks-2.4.2.tar.gz $ tar zxpf luarocks-2.4.2.tar.gz
$ cd luarocks-2.4.2
$ export prefix=$(dirname $(dirname $(which lua)))
$ ./configure --prefix=$prefix  --sysconfdir=$prefix/luarocks --force-config --with-lua=$prefix

$ make bootstrap
$ luarocks

lua项目构建

$ mkdir rocktest
$ cd rocktest && mkdir -p src/spec
$ luarocks write_rockspec  --lua-version=5.3  rocktest 1.0.0 ./
# 上面这里是新建了一个.rockspec配置文件,rocktest项目名称,1.0.0版本号

$ touch src/first.lua && echo "print('hello');return {}" > src/first.lua
$ vim *.rockspec
#  如果要构建库
modules = {first = "src/first.lua"}
# 如果要构建可执行文件:
,install = {
bin = {
['sometest'] = 'bin/sometest'
}
}
$ mkdir bin && echo "require 'first' "  > bin/sometest
$ luarocks make


更详细配置,参见

lua测试工具安装

安装busted

$ luarocks install busted
$ touch rocktest/spec/test_spec.lua   #以 _spec结尾


文件test_spec.lua添加测试内容,比如:

describe('Tests the busted pending functions through the commandline', function()

it('is a test with a pending', function()
pending('finish this test later')
error('should never get here')
end)

pending('is a pending inside a describe', function()
it('this test does not run', function()
error('this should not run')
end)
end)
end)


测试用例

开始测试

$ busted
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  lua