lua-users home
lua-l archive

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

* Jerome Vuarand <> [15/04/14 18:59]:

> Why do you need to distinguish the case when a Lua table is actually
> an array? If you can store an arbitrary map, Lua arrays are just a
> special case of that. In other words:
> function convert_stack_to_set(...)
>     local set = {}
>     local n = 1
>     for each stack value do
>         set[n] = value

No, set elements must be lists, i.e. sequences of fields.
Here we may break this rule if the value is a map or a scalar.

We could convert each stack element to a list with one field, but
then there would be no way to return a list with many fields,
even if the user wanted to do so.

>         n = n + 1
>     end
>     set.n = n -- if you care about trailing nils
>     return set
> end

-- - a NoSQL database in a Lua script