Page MenuHomePhabricator

Lua table serialization (dumping contents of a table) is really painful/annoying
Closed, ResolvedPublic

Description

I'm trying to debug a Lua module. Here's my test input:


function test(frame)
local t = {}
t[1] = 2
return t
end

print(test())

This input returns the string "table". This is really unhelpful and very annoying. I want to dump the table. The string "table" provides almost no value to me at all.

It would be very helpful to have a function that can print something similar to this:


print_table(t)

t = { 1 = 2 }

Looking around the Web, it seems that this is a fairly common issue in Lua:

I'd like for there to be a built-in function (similar to print_r or var_dump in PHP or the print statement in Python 2) that allows easy dumping/printing/serialization of a Lua table for debugging purposes.


Version: unspecified
Severity: enhancement

Details

Reference
bz48173

Event Timeline

bzimport raised the priority of this task from to Low.Nov 22 2014, 1:44 AM
bzimport added a project: Scribunto.
bzimport set Reference to bz48173.
bzimport added a subscriber: Unknown Object (MLST).

Change 70857 had a related patch set uploaded by Anomie:
Add mw.logObject

https://gerrit.wikimedia.org/r/70857

Change merged. It should be deployed to WMF wikis with 1.22wmf13.

Change 95414 had a related patch set uploaded by MarkAHershberger:
Add mw.logObject

https://gerrit.wikimedia.org/r/95414

Change 95414 abandoned by MarkAHershberger:
Add mw.logObject

https://gerrit.wikimedia.org/r/95414

No open patches to review here (backport patches got abandoned), hence resetting status to RESOLVED FIXED. Backport_to_Stable flag might be set to "-" by hexmode.