<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-GB">
	<id>https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FJohnuniq%2Fdebug</id>
	<title>Module:Sandbox/Johnuniq/debug - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://stockhub.co/index.php?action=history&amp;feed=atom&amp;title=Module%3ASandbox%2FJohnuniq%2Fdebug"/>
	<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Johnuniq/debug&amp;action=history"/>
	<updated>2026-04-21T02:06:47Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.43.5</generator>
	<entry>
		<id>https://stockhub.co/index.php?title=Module:Sandbox/Johnuniq/debug&amp;diff=145627&amp;oldid=prev</id>
		<title>imported&gt;Johnuniq: add demo of mw.logObject(t) and mw.dumpObject(t) where t is a complex table</title>
		<link rel="alternate" type="text/html" href="https://stockhub.co/index.php?title=Module:Sandbox/Johnuniq/debug&amp;diff=145627&amp;oldid=prev"/>
		<updated>2019-04-22T03:44:38Z</updated>

		<summary type="html">&lt;p&gt;add demo of mw.logObject(t) and mw.dumpObject(t) where t is a complex table&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;--[=[ Module:Sandbox/Johnuniq/debug&lt;br /&gt;
&lt;br /&gt;
-- Whatever is pasted in the debug console is interpreted as a single command.&lt;br /&gt;
-- That means you cannot paste, say, two lines where each is a command.&lt;br /&gt;
&lt;br /&gt;
-- In the debug console, can get the current frame and pass it to main.&lt;br /&gt;
-- Setting args has no effect.&lt;br /&gt;
f = mw.getCurrentFrame()&lt;br /&gt;
f.args[1] = &amp;#039;Ignored&amp;#039;&lt;br /&gt;
f.args[2] = 42&lt;br /&gt;
=mw.logObject(f, &amp;#039;f&amp;#039;)&lt;br /&gt;
=p.main(f)&lt;br /&gt;
&lt;br /&gt;
-- Can create a child frame with specified args.&lt;br /&gt;
f2 = f:newChild({title=&amp;#039;MyTitle&amp;#039;, args={120,94321,name=&amp;#039;hello&amp;#039;,&amp;#039;{{convert|12|kg}}&amp;#039;}})&lt;br /&gt;
f3 = mw.getCurrentFrame():newChild({title=&amp;#039;MyTitle&amp;#039;, args={120,94321,name=&amp;#039;hello&amp;#039;,&amp;#039;{{convert|12|kg}}&amp;#039;}})&lt;br /&gt;
=mw.logObject(f2, &amp;#039;f2&amp;#039;)&lt;br /&gt;
=p.main(f2)&lt;br /&gt;
=p.main(f3)&lt;br /&gt;
&lt;br /&gt;
-- If main uses Module:Arguments, can pass a table to main.&lt;br /&gt;
-- That means argument values may be any data type (normally, arguments are strings).&lt;br /&gt;
-- main gets a table, not a frame, so methods like frame:getTitle() cannot be used.&lt;br /&gt;
=p.mainargs({11, 22, name=&amp;#039;hello&amp;#039;, &amp;#039;more&amp;#039;, number=420})&lt;br /&gt;
&lt;br /&gt;
-- See talk for examples of displaying a table.&lt;br /&gt;
&lt;br /&gt;
]=]&lt;br /&gt;
&lt;br /&gt;
local function spell(number)&lt;br /&gt;
	local names = {[0] = &amp;#039;Zero&amp;#039;, &amp;#039;One&amp;#039;, &amp;#039;Two&amp;#039;, &amp;#039;Three&amp;#039;, &amp;#039;Four&amp;#039;, &amp;#039;Five&amp;#039;, &amp;#039;Six&amp;#039;, &amp;#039;Seven&amp;#039;, &amp;#039;Eight&amp;#039;, &amp;#039;Nine&amp;#039;}&lt;br /&gt;
	if number &amp;gt;= 200 then&lt;br /&gt;
		mw.log(&amp;#039;number = &amp;#039; .. number)&lt;br /&gt;
		mw.logObject(names, &amp;#039;names&amp;#039;)&lt;br /&gt;
	end&lt;br /&gt;
	local digits = &amp;#039;&amp;#039;&lt;br /&gt;
	repeat&lt;br /&gt;
		local unit = number % 10&lt;br /&gt;
		number = math.floor(number / 10)&lt;br /&gt;
		digits = names[unit] .. digits&lt;br /&gt;
	until number == 0&lt;br /&gt;
	return digits&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function listArgs(frame, args)&lt;br /&gt;
	local results, n = {}, 0&lt;br /&gt;
	local function add(k, v)&lt;br /&gt;
		n = n + 1&lt;br /&gt;
		if type(k) == &amp;#039;string&amp;#039; then&lt;br /&gt;
			k = &amp;#039;&amp;quot;&amp;#039; .. k .. &amp;#039;&amp;quot;&amp;#039;&lt;br /&gt;
		end&lt;br /&gt;
		results[n] = &amp;#039;parameter &amp;#039; .. tostring(k) .. &amp;#039;, value &amp;#039; .. tostring(v)&lt;br /&gt;
	end&lt;br /&gt;
	for k, v in pairs(args) do&lt;br /&gt;
		add(k, v)&lt;br /&gt;
		if tonumber(v) then&lt;br /&gt;
			add(&amp;#039;...spelled&amp;#039;, spell(tonumber(v)))&lt;br /&gt;
		elseif type(v) == &amp;#039;string&amp;#039; and v:sub(1, 2) == &amp;#039;{{&amp;#039; then&lt;br /&gt;
			add(&amp;#039;...expanded&amp;#039;, frame:preprocess(v))&lt;br /&gt;
		end&lt;br /&gt;
	end&lt;br /&gt;
	local extra = frame.getTitle and (&amp;#039;Title &amp;#039; .. frame:getTitle()) or &amp;#039;(not frame)&amp;#039;&lt;br /&gt;
	return extra .. &amp;#039;\n&amp;#039; .. table.concat(results, &amp;#039;\n&amp;#039;)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function main(frame)&lt;br /&gt;
	return listArgs(frame, frame.args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function mainargs(frame)&lt;br /&gt;
	local args = require(&amp;#039;Module:Arguments&amp;#039;).getArgs(frame)&lt;br /&gt;
	return listArgs(frame, args)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
local function dump(frame)&lt;br /&gt;
	local testcase = require(&amp;#039;Module:Dump&amp;#039;).testcase(&amp;#039;return table&amp;#039;)&lt;br /&gt;
	mw.logObject(testcase)  -- result can be seen when previewing an edit of a page calling this function&lt;br /&gt;
	return mw.dumpObject(testcase)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return {&lt;br /&gt;
	main = main,&lt;br /&gt;
	mainargs = mainargs,&lt;br /&gt;
	dump = dump,&lt;br /&gt;
}&lt;/div&gt;</summary>
		<author><name>imported&gt;Johnuniq</name></author>
	</entry>
</feed>