Skip to content

Instantly share code, notes, and snippets.

@sofar
Created June 21, 2015 20:50
Show Gist options
  • Save sofar/41d1e70893f16d457ff1 to your computer and use it in GitHub Desktop.
Save sofar/41d1e70893f16d457ff1 to your computer and use it in GitHub Desktop.
init.lua - dump lua global table with table element size estimate
minetest.register_chatcommand("dump", {
params = "",
description = "Dump all objects in the global table",
func = function()
print("_G has "..#_G.." elements")
for k,v in pairs(_G) do
if k~="_G" then
if type(v)=="string" or type(v)=="number" then
print("G["..k.."]="..v)
elseif type(v)=="table" then
print("G["..k.."]=("..type(v)..")="..string.len(tostring(k)..tostring(v)))
else
print("G["..k.."]=("..type(v)..")")
end
end
end
return true, "Table dumped to console"
end
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment