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

发布时间:2022-04-19 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了Lua编程示例(一):select、debug、可变参数、table操作、error脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
function test_PRint(...)
 for i=1,select("#",...) do
 print(i,select(i,...))
 end
end

test_print(11,12,13,14)


print()
print(debug.traceback())
print()

function test(...)
 for i=1,arg.n do
 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,
})
function myprint()
 for i,v in ipairs(g) do
 print(i,v["level"],v.name)
 end
end

myprint()
function comp(a,b)
 return a.level<b.level
end
table.sort(g,comp)

print()
myprint()

print()
function foo(str)
 if tyPE(str) ~= "string" then
 error("string error!",2)
 end
end

--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)
end
print(#tb1)


运行结果为:

1 11 12 13 14
2 12 13 14
3 13 14
4 14

stack traceback:
 my_test.lua:12: in main chunk
 [C]: ?

1 a
2 2
3 34
4 234

1 70 Clairs
2 35 SEGA
3 50 Millber

1 35 SEGA
2 50 Millber
3 70 Clairs

asdf
haha
game
3


脚本宝典总结

以上是脚本宝典为你收集整理的Lua编程示例(一):select、debug、可变参数、table操作、error全部内容,希望文章能够帮你解决Lua编程示例(一):select、debug、可变参数、table操作、error所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。