Lua Quick Start
2014年左右,在组内做分享时写的一个文档,最近翻出来了,在这里记录下 variable num = 42 str = ‘hello’ is_ok = false t = {key1 = 'value1', key2 = false} u = {['@!#'] = 'qbert', [{}] = 1729, [6.28] = 'tau'} print(u[6.28]) -- prints "tau" for key, val in pairs(u) do print(key, val) end v = {'value1', 'value2', 1.21, 'gigawatts'} for i = 1, #v do print(v[i]) end function fib(n) if n < 2 then return 1 end return fib(n - 2) + fib(n - 1) end flow control if if num > 40 then print('over 40') elseif s ~= 'walternate' then -- ~= is not equals. io.write('not over 40\n') -- Defaults to stdout. else -- Variables are global by default. thisIsGlobal = 5 -- Camel case is common. -- How to make a variable local: local line = io.read() -- Reads next stdin line. -- String concatenation uses the .. operator: print('Winter is coming, ' .. line) end for loop ...