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


 本篇博客出自  阿修罗道,转载请注明出处:http://blog.csdn.net/fansongy/article/details/7005142

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值