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

安装目录linux

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

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测试工具安装

$ 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
相关文章
相关标签/搜索