lua-users home
lua-l archive

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


On 10 Nov 2012, at 18:50, spir wrote:


> To print an array, object, whatever... in "tree view" with indentation, we need to pass a nesting/indent level, and also the set of previously visited tables to avoid inf recursion. 

Would your tree contain numbers and strings? How do you intend to overload to string for them?

The purpose of tostring is to convert its argument to string form, not to make it pretty printable as part of a tree. Why not implement __to_tree_view in the metatable of your objects you want to print and then implement a global treeview function which calls the metafunction if present and print some tabs followed by tostring otherwise.

Kev