lua-users home
lua-l archive

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


Hello,

There has been a short thread upon having "out of the box" tables equipped with methods defined on standard library "table" (insert, sort,...), like is done for strings and files. The advantage beeing to be able to write eg t:sort() instead of table.sort(t).

Maybe an option would also be to have access to real types ('table', as well as 'string', file',...) that would really be used to create objects. For the programmer, it would then be possible to equip such types at will by defining, updating, or extending the metatable.
This means that new objects would be assigned the metatable defined on the type, at creation time.
It would also make possible to easily subtype builtin types (eg to define Sequence or Set) and inherit the base behaviour  through the parent's metatable.

Note that this cannot replace the "out of the box" equipment for methods that map to no operator (eg sort). Except if the additional methods would be defined on a distinct method container (eg table_lib), from which methods then could be set at will on the real type. This means the types would have an __index pointing to themselves.

(Well, actually I'm not sure there is no easy way to do all that in lua already.)

Denis
________________________________

la vita e estrany

http://spir.wikidot.com/