首页 > 开发 > 综合 > 正文

Lua编程示例(一):select、debug、可变参数、table操作、error

2024-07-21 23:04:58
字体:
来源:转载
供稿:网友
function test_print(...) for i=1,select("#",...) do print(i,select(i,...)) endendtest_print(11,12,13,14)print()print(debug.traceback())print()function test(...) for i=1,arg.n do print(i.."/t"..arg[i]) endendtest("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,})function myprint() for i,v in ipairs(g) do print(i,v["level"],v.name) endendmyprint()function comp(a,b) return a.level<b.levelendtable.sort(g,comp)print()myprint()print()function foo(str) if type(str) ~= "string" then error("string error!",2) endend--foo({x =1 })tb1={ "asdf","bate","game",one="heihei"}table.insert(tb1,3,"haha")table.remove(tb1,2)for i,v in ipairs(tb1) do print(v)endprint(#tb1)

 


运行结果为:

1 11 12 13 142 12 13 143 13 144 14stack traceback: my_test.lua:12: in main chunk [C]: ?1 a2 23 344 2341 70 Clairs2 35 SEGA3 50 Millber1 35 SEGA2 50 Millber3 70 Clairsasdfhahagame3

 

 
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表