幾種語言原生開發環境構建之--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
相關文章
相關標籤/搜索