Lua语法与C语言有些相似也不太一样,写了语句学一下 微笑
--begin
a = --[[explain]] "ha";
print(a)
if a == "ha" then
print("if test passed")
else
print("if used wrong")
end
b,c=2,3
print(b,c)
b,c=c,b
if b==3 and c==2 then
print("swap test passed")
print(b,c)
else
print("swap error")
end
do
b = 6
if b==6 then
print("code block test passed")
else
print("code block test error")
end
end
do
d=true;
local e="haha"
end
if d==true and e==nil then
print("local test passed")
else
print("local test error")
end
c = 2^3
if c == 8 then
print("squert test passed")
else
print("test error")
end
a = "string will be ".."connected"
print(a)
x = x or a --if not x then x = v end
print(x)
print(type(asdf))
c=3-1.2;
print(c)
d = [[
怎么会
怎么会
你竟原谅了我"the num is "..w)
local add=w+1
return add;
end
b=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" ha if test passed 2 3 swap test passed 3 2 code block test passed local test passed squert test passed string will be connected string will be connected nil 1.8 怎么会 怎么会 你竟原谅了我? the num is 5 nil 6 nil 100 I'm the 100th element 22 20 13 >Exit code: 0
标签:
Lua,脚本语言,基本语法
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件!
如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
暂无“Lua脚本语言基本语法快速入门教程”评论...
更新动态
2025年10月27日
2025年10月27日
- 小骆驼-《草原狼2(蓝光CD)》[原抓WAV+CUE]
- 群星《欢迎来到我身边 电影原声专辑》[320K/MP3][105.02MB]
- 群星《欢迎来到我身边 电影原声专辑》[FLAC/分轨][480.9MB]
- 雷婷《梦里蓝天HQⅡ》 2023头版限量编号低速原抓[WAV+CUE][463M]
- 群星《2024好听新歌42》AI调整音效【WAV分轨】
- 王思雨-《思念陪着鸿雁飞》WAV
- 王思雨《喜马拉雅HQ》头版限量编号[WAV+CUE]
- 李健《无时无刻》[WAV+CUE][590M]
- 陈奕迅《酝酿》[WAV分轨][502M]
- 卓依婷《化蝶》2CD[WAV+CUE][1.1G]
- 群星《吉他王(黑胶CD)》[WAV+CUE]
- 齐秦《穿乐(穿越)》[WAV+CUE]
- 发烧珍品《数位CD音响测试-动向效果(九)》【WAV+CUE】
- 邝美云《邝美云精装歌集》[DSF][1.6G]
- 吕方《爱一回伤一回》[WAV+CUE][454M]