Skip to content

Instantly share code, notes, and snippets.

@Zbizu
Last active December 24, 2023 13:38
Show Gist options
  • Save Zbizu/1bd1b3001c1b50cd23011a9ca0f4c689 to your computer and use it in GitHub Desktop.
Save Zbizu/1bd1b3001c1b50cd23011a9ca0f4c689 to your computer and use it in GitHub Desktop.
get all Lua functions (and globals)
-- usage: just call it in a Lua environment and look for a file called out.txt
-- lists all global variables in a file
function writeAllGlobals()
local file = io.open("out.txt", "w+")
local seen={}
local function dump(t,i)
seen[t]=true
local s={}
local n=0
for k, v in pairs(t) do
n=n+1
s[n]=tostring(k)
end
table.sort(s)
for k,v in ipairs(s) do
file:write(i .. v .. "\n")
v=t[v]
if type(v)=="table" and not seen[v] then
dump(v,i.."\t")
end
end
end
dump(_G,"")
file:close()
end
-- version with print
-- can be tested here: https://www.lua.org/cgi-bin/demo
function printAllGlobals()
local seen={}
local function dump(t,i)
seen[t]=true
local s={}
local n=0
for k, v in pairs(t) do
n=n+1
s[n]=tostring(k)
end
table.sort(s)
for k,v in ipairs(s) do
print(i .. v)
v=t[v]
if type(v)=="table" and not seen[v] then
dump(v,i.."\t")
end
end
end
dump(_G,"")
end
-- printAllGlobals()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment