Lua编程示例(一):select、debug、可变参数、table操作、error
functiontest_print(...)
fori=1,select("#",...)do
print(i,select(i,...))
end
end
test_print(11,12,13,14)
print()
print(debug.traceback())
print()
functiontest(...)
fori=1,arg.ndo
print(i.."\t"..arg[i])
end
end
test("a",2,34,234)
print()
g={}
table.insert(g,{
name="Clairs",
level=70,
})
table.insert(g,{
name="SEGA",
level=35,
})
table.insert(g,{
name="Millber",
level=50,
})
functionmyprint()
fori,vinipairs(g)do
print(i,v["level"],v.name)
end
end
myprint()
functioncomp(a,b)
returna.level<b.level
end
table.sort(g,comp)
print()
myprint()
print()
functionfoo(str)
iftype(str)~="string"then
error("stringerror!",2)
end
end
--foo({x=1})
tb1={"asdf","bate","game",one="heihei"}
table.insert(tb1,3,"haha")
table.remove(tb1,2)
fori,vinipairs(tb1)do
print(v)
end
print(#tb1)
运行结果为:
111121314 2121314 31314 414 stacktraceback: my_test.lua:12:inmainchunk [C]:? 1a 22 334 4234 170Clairs 235SEGA 350Millber 135SEGA 250Millber 370Clairs asdf haha game 3
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下