Lua脚本语言基本语法快速入门教程
技术  /  管理员 发布于 4年前   129
Lua语法与C语言有些相似也不太一样,写了语句学一下 微笑
--begina = --[[explain]] "ha";print(a)if a == "ha" then print("if test passed")else print("if used wrong")endb,c=2,3print(b,c)b,c=c,bif b==3 and c==2 then print("swap test passed") print(b,c)else print("swap error")enddo b = 6 if b==6 then print("code block test passed") else print("code block test error") endenddo d=true; local e="haha"endif d==true and e==nil then print("local test passed")else print("local test error")endc = 2^3if c == 8 then print("squert test passed")else print("test error")enda = "string will be ".."connected"print(a)x = x or a --if not x then x = v endprint(x)print(type(asdf))c=3-1.2;print(c)d = [[怎么会 怎么会 你竟原谅了我?]]print(d)function test (w) print("the num is "..w) local add=w+1 return add;endb=test(5)print(add,b)t={ 100, [100] = "I'm the 100th element", fsy= { ['age']=22, sex = "male", --如果是字符串,可以去掉引号和括号 },--元素之间必须用,隔开 20, -- 相当于t[2]=20}print(t[0])print(t[1])print(t[100])print(t.fsy.age)print(t[2])g = { age = 3, add=function (s,n) s.age=s.age+n end}g:add(10) --相当于g.add(g,10)print(g.age)
运行的结果如下:
>lua -e "io.stdout:setvbuf 'no'" "hello.lua" haif test passed2 3swap test passed3 2code block test passedlocal test passedsquert test passedstring will be connectedstring will be connectednil1.8怎么会 怎么会 你竟原谅了我?the num is 5nil 6nil100I'm the 100th element222013>Exit code: 0
123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..路人 在
php中使用hyperf框架调用讯飞星火大模型实现国内版chatgpt功能示例中评论 教程很详细,如果加个前端chatgpt对话页面就完美了..Copyright·© 2019 侯体宗版权所有· 粤ICP备20027696号