Lua丨元表——__tostring,lua丨__tostring
分享于 点击 33113 次 点评:243
Lua丨元表——__tostring,lua丨__tostring
--将表当作函数使用,输出表组合在一起的内容
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
相关文章
- 暂无相关文章
用户点评