local function printMetaTableFun(t)
local rs_tb={}
local function tmp(t)
if t then
for _val, _val_type in pairs(t) do
if type(_val_type)~="userdata" then
if not string.find(_val,"_") then
table.insert(rs_tb,_val)
end
end
end
local ft=getmetatable(t)
if ft then
tmp(ft)
end
end
end
tmp(getmetatable(t))
table.sort(rs_tb)
local rs_str=""
for i=1,#rs_tb do
rs_str=rs_str .. rs_tb[i] .. "\n"
end
print(rs_str)
end

本文介绍了一种在Lua中遍历元表并收集非userdata类型值的实用函数。通过递归方式,该函数能够深入查找并整理元表中的所有可打印元素,最终按字母顺序输出,为调试和理解元表结构提供了便利。
2183

被折叠的 条评论
为什么被折叠?



