lua-users home
lua-l archive

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


>> I still feel the lack of an efficient way to determine if a table t is a
>> sequence is a significant hole in the language/runtime.
>
> Why would you need that? If you care that a table is a sequence, then
> either
> you have created the table and know it or you have been handed a table and
> can assume whoever gave you the table honors the contract with you to use
> only sequences. What am I missing?

I may be repeating something I have said countless times, but...

If you write a library that takes a rather generic Lua table which can be
nested, you need this. An example of that is anything that serializes a
data structure (the most well-known example being serializing to JSON).

You can work around that issue by letting the caller provide the library a
way to distinguish between sequential and associative types (e.g. [1]) but
this makes APIs more complex.

Personally I still think Lua would be better with a real native sequential
type...

[1]
https://github.com/harningt/luajson/blob/master/lua/json/encode/array.lua#L31

-- 
Pierre Chapuis