测试Lua环境是否已经安装:
adeMacBook-Pro:perl_dev apple$ lua -bash: lua: command not found
如果没有的话就到lua官方去下载:(网址:http://www.lua.org/download.html)
参考说明:
make的时候 是指定macosx
adeMacBook-Pro:lua_soft apple$ curl -R -O http://www.lua.org/ftp/lua-5.3.0.tar.gz % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0 0 0 0 0 0 0 0 0 --:--:-- 0:00:04 --:--:-- 0 5 271k 5 15508 0 0 2238 0 0:02:04 0:00:06 0:01:58 3533 100 271k 100 271k 0 0 31308 0 0:00:08 0:00:08 --:--:-- 83547
curl -R -O http://www.lua.org/ftp/lua-5.3.0.tar.gz tar zxf lua-5.3.0.tar.gz cd lua-5.3.0 make linux test
测试安装成功与否和版本号是否正确
adeMacBook-Pro:lua-5.3.0 apple$ lua Lua 5.3.0 Copyright (C) 1994-2015 Lua.org, PUC-Rio
查看Lua的目录
adeMacBook-Pro:lua-5.3.0 apple$ which lua /usr/local/bin/lua
配置SubmlineText中Lua环境Tool->Build System -> New Build System中添加代
{ "cmd": ["/usr/local/bin/lua", "$file"], "file_regex": "^(...*?):([0-9]*):?([0-9]*)", "selector": "source.lua" }
然后保存为Lua.sublime-build.
第四步:新建一个HelloWorld.lua文件,随便输入语句,然后选择Lua为build System,按一下command+b
附一段小程序:
adeMacBook-Pro:lua_dev apple$ vim hel.lua
-- Fibonacci sequence with coroutines function fibo() a, b = 0, 1 while true do coroutine.yield(a) a, b = b, a + b end end co = coroutine.create(fibo) n = arg[1] or 20 for i = 0, n do print(i,coroutine.resume(co)) end
adeMacBook-Pro:lua_dev apple$ lua hel.lua 0 true 0 1 true 1 2 true 1 3 true 2 4 true 3 5 true 5 6 true 8 7 true 13 8 true 21 9 true 34 10 true 55 11 true 89 12 true 144 13 true 233 14 true 377 15 true 610 16 true 987 17 true 1597 18 true 2584 19 true 4181 20 true 6765
时间: 2024-10-24 18:02:22