-
-
Save Codinablack/c06309fdb048bb2340f68820b6f5cb9e to your computer and use it in GitHub Desktop.
get all Lua functions (and globals)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| -- 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