lua-users home
lua-l archive

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


On 2012-02-14 16:44, KR wrote:
Pierre Chapuis <catwell <at> archlinux.us> writes:

I am confused, you can indeed add "markers" (via weak tables if you
prefer a not
invasive approach) allowing a syntax like:

example = M{
   a = A{1,2,3},
   b = M{a = 1, b = 2, c = A{1,2}},
}

Would this be fine?

This is what I meant by "In your own code you can choose a way to
flag a table as a List/Array or a Map". You can enforce a convention
like that in your library but it is not something standard. If you
already have a "standard" Lua structure composed of tables and
basic types you cannot determine what is Array-like without
iterating every single table in the structure.

Examples of this can be found (for instance) at [1] and [2].

[1] https://github.com/harningt/luajson/blob/master/lua/json/encode/array.lua#L36 [2] https://github.com/catwell/luajit-msgpack-pure/blob/master/luajit-msgpack-pure.lua#L168

--
Pierre 'catwell' Chapuis