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
热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短