Lua丨元表——__tostring

版权声明:欢迎转载,转载请注明出处 https://blog.csdn.net/weixin_38239050/article/details/82530677
--将表当作函数使用,输出表组合在一起的内容
mytable={"lua","java","c#"}

mymetatable={
__tostring=function(mytable)
	local str=""
	for k,v in pairs(mytable) do
		str=str..v..","
	end
	return str
end
}

mytable=setmetatable(mytable,mymetatable)

print(mytable)



>lua -e "io.stdout:setvbuf 'no'" "table.lua" 
lua,java,c#,
>Exit code: 0

猜你喜欢

转载自blog.csdn.net/weixin_38239050/article/details/82530677