-- basic.luaprint("hello ".."world")local a =1--only this file can see
b =2-- global see-- not declare vaiable all asign to nilprint(fuck)-- 字符串可以"" ,'' ,[[]]-- 一些数值运算支持,进制数,科学数,shift移functionf(a,b)print(a,b)return a + b,a - b
endlocal sum,sub =f(1,2)--tablelocal arr ={1,"hell",{},function()end}-- index start from 1print(arr[4])print(#arr)
table.insert(arr,1,"fuck")local name_table ={a=1,b="1111",c=function()return"yes"end,d={}}print(name_table["c"])--get the value--全局表_Gprint(_G["table"]["insert"])print(_G["b"])-- see the above global vaiable b-- control flowif1+1==2thenprint(true)elseif1+1==3and1+1==0thenprint(false)--0 is true,only nil is falseelseprint("what ever")end-- start end stepfor i=10,1,-1doprint(i)--this i just can read not writeif i ==5thenbreakendendlocal n =10while n >1doprint(n)n = n -1--not support -- ++if n==5thenbreakendend-- this module can return varluereturn1
-- multi-file.lua-- auto run the file basic.lua codelocal basic =require("basic")--and get the return from file basic.luaprint("b is ",b)-- get the basic global vaiable bprint(basic)print(package.path)--?.lua, ?会被文件名替代
-- example.lualocal example ={}function example.hello()print("hello")endreturn example
-- use-example.lualocal example =require("example")
example.hello()