lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

Here's my version!

Handles cycles and generally creates the shortest serialization (though you can probably find some corner cases that doesn't do this!)

Output from the test at the bottom:
test 1:{1,2,3}
test 2:{1,2,3}
test 1:{hello="world",foo="bar"}
test 2:{hello="world",foo="bar"}
test 1:{1,2,3,[100]=4}
test 2:{1,2,3,[100]=4}
test 1:{1,2,34,45,hello="world"}
test 2:{1,2,34,45,hello="world"}
test 1:_(2,{t2=_(1,{t2=_(1),t1=_(2)}),t1=_(2)})
test 2:_(2,{t2=_(1,{t2=_(1),t1=_(2)}),t1=_(2)})
test 1:_(1,{1,2,4,[_(1)]=_(1),x=_(2,{x=_(2)}),asd="asdff"})
test 2:_(1,{1,2,4,[_(1)]=_(1),x=_(2,{x=_(2)}),asd="asdff"})

On Tue, Nov 10, 2009 at 8:56 PM, Steven Johnson <> wrote:
Another debugging one here. This one takes a formatted output function
(and you can register one to act as the default) and
then applies that line-by-line. The line-by-line thing lets us dump to
arrays or other structures (e.g. a vector or linked list of
strings on the C side), which can sometimes be easier to traverse.
Also handles cycles and arbitrary keys, and respects
__tostring; it ignores metatable and environment, though maybe I'll
add those as options some day.


function printf (format, ...)
 print(string.format(format, ...))

var_dump.Print(MyVariable, printf) -- Accepts any value, tables are
just a special case



License is MIT.