-- ThoughtDump v1.1
-- Created by Thought (http://hw2.tproc.org)
-- Edited by Mikail

function __Prefix(level)
	local prefix = ""
	if level < 1 then
		return ""
	end
	for i = 1, level, 1 do
		prefix = prefix .. "	"
	end
	return prefix
end

function __Comma(level)
	if level > 0 then
		return ","
	end
	return ""
end

function __Parse(name, value, level)
	level = level + 1
	if type(value) == "function" then
		print(__Prefix(level) .. "function " .. name .. "()" .. __Comma(level))
	elseif type(value) == "string" then
		if type(name) == "string" then
			print(__Prefix(level) .. name .. " = \"" .. value .. "\"" .. __Comma(level))
		else
			print(__Prefix(level) .. "\"" .. value .. "\"" .. __Comma(level))
		end
	elseif type(value) == "number" then
		if type(name) == "string" then
			print(__Prefix(level) .. name .. " = " .. value .. __Comma(level))
		else
			print(__Prefix(level) .. value .. __Comma(level))
		end
	elseif type(value) == "table" then
		if type(name) == "string" then
			print(__Prefix(level) .. name .. " = {")
		else
			print(__Prefix(level) .. "{")
		end
		for i, v in value do
			__Parse(i, v, level)
		end
		print(__Prefix(level) .. "}" .. __Comma(level))
	else
		print(__Prefix(level) .. name .. " = \"unknown type: " .. type(value) .. "\"" .. __Comma(level))
	end
end

__Parse("globals", globals(), -1)
