[DEVS] Function Dump
#1
After playing around with the existing functions etc. I made a quick plugin to dump the global table of functions and tables to a text file.

I wasn't quite sure where to post it, but seeing as it's in plugin form, I posted it here.

Function Dump Plugin Download
Function Dump Text File (03/02/14) Download

Function to dump global table:
function PrintTables()
	local content = ""
	local content2 = ""
	for k, v in pairs(_G) do
		if type(v) == "function" then
			content = content..tostring(k).."\n"
		elseif type(v) == "table" then
				for i, z in pairs(v) do
					if type(z) == "function" then
						if tostring(k) ~= "_G" then
							content2 = content2..tostring(k).."."..tostring(i).."\n"
						end
					end
				end
		end
	end
	local file = io.open("Plugins/FunctionDump/data.txt", "w")
	file:write(content)
	file:write(content2)
	file:close()
end
Reply
Thanks given by:
#2
Do correct me, but does this not do the same as what APIDump does?
Reply
Thanks given by:
#3
No, this simply prints the name of the global functions and tables. APIDump is what prints and displays the API documentation for on the main web page. http://mc-server.xoft.cz/LuaAPI/

PS: I made this before I even knew about APIDump and had to quickly look into it to make sure I wasn't going to embarrass myself.Tongue
Reply
Thanks given by:
#4
I think this does what an early version of APIDump did Wink
Reply
Thanks given by:
#5
That code won't print two-levels-deep tables, although I don't think we're using any of those, so it doesn't matter much. Be careful though of recursion - "_G" table contains all the globals, including itself, so "_G._G" is a table again, etc. Your code will print at least global functions twice - "assert" and "_G.assert".
Reply
Thanks given by:
#6
(02-04-2014, 04:59 AM)xoft Wrote: That code won't print two-levels-deep tables, although I don't think we're using any of those, so it doesn't matter much. Be careful though of recursion - "_G" table contains all the globals, including itself, so "_G._G" is a table again, etc. Your code will print at least global functions twice - "assert" and "_G.assert".
Fixed in the code in OP.
Reply
Thanks given by:
#7
Now the code is quite inefficient, the check for _G on line 10 either fails or succeeds for all iterations over i, so there's no point in putting it into the innermost for-loop. And k is already a string, no need to tostring() it.
Reply
Thanks given by:




Users browsing this thread: 4 Guest(s)