lua-users home
lua-l archive

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


Hi,

Try this code:

table.foreach(t, print)

This table.foreach is a function to map algorithm (see
http://en.wikipedia.org/wiki/Map_(higher-order_function)).

Perhaps, you can write this:

function inspect(key, value)
  local prefix = name
  local out = prefix and prefix..".%s" or "%s"
  if type(value) == "table" then
    name = prefix.."."..key
    table.foreach(value, inspect)
    name = prefix
  else
    out = type(value) == "function" and out.."()" or out.." = %s"
    print(out:format(key, tostring(value)))
  end
end

name = "t"
table.foreach(t, inspect)

Don't run this code using the _G table. The C stack overflow is
throwed because _G has a reference to yourself.

Regards.

On Fri, May 4, 2012 at 1:22 PM, Petite Abeille <petite.abeille@gmail.com> wrote:
>
> On May 4, 2012, at 7:15 PM, Emeka wrote:
>
>> I would want to use a print-like function to do the following:
>
> http://lua-users.org/wiki/TableSerialization
>
>



-- 
Hallison Batista
hallison.batista@gmail.com