Cuberite Forum
[DEVS] Function Dump - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Releases (https://forum.cuberite.org/forum-2.html)
+---- Forum: Archived Plugins (https://forum.cuberite.org/forum-18.html)
+---- Thread: [DEVS] Function Dump (/thread-1349.html)



[DEVS] Function Dump - Jarva - 02-04-2014

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



RE: [DEVS] Function Dump - tigerw - 02-04-2014

Do correct me, but does this not do the same as what APIDump does?


RE: [DEVS] Function Dump - Jarva - 02-04-2014

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


RE: [DEVS] Function Dump - NiLSPACE - 02-04-2014

I think this does what an early version of APIDump did Wink


RE: [DEVS] Function Dump - xoft - 02-04-2014

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".


RE: [DEVS] Function Dump - Jarva - 02-04-2014

(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.


RE: [DEVS] Function Dump - xoft - 02-04-2014

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.