Module:Sandbox/Nihiltres/Testing

This is an old revision of this page, as edited by Nihiltres (talk | contribs) at 21:24, 13 May 2016 (A convenience for later testing, now that I've done testing via preview :P). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
p = {}

function p.main (frame)
	foo = 'Result of tested Lua snippet would be here.'
	
	returnVal = foo
	if type(returnVal) == 'table' then
		function tableRender (tbl, level)
			level = level or 0
			--maxLevel avoids recursive issues; adjust as needed
			maxLevel = 4
			if level > maxLevel then return tostring(tbl) end
			tab = ''
			for i = 1, (level * 4) do tab = tab .. " " end
			local text = ''
			for k,v in pairs(tbl) do
				if v == tbl then return tostring(tbl) end
				text = text..'\n\n'..tab..k..":"
				if type(v) == 'table' then
					text = text .. tableRender(tbl, level + 1)
				else
					text = text..v
				end
			end
			return text
		end
		return tableRender(returnVal)
	else
		return tostring(returnVal)
	end
end

return p