lua-users home
lua-l archive

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


Hi guys,

Any Lua type can have a metatable (apart from userdata and tables) but
it applies to every instance of that type. This is very useful (e.g.
allowing things like s:sub(1,-2)) but sometimes it would be very
_cool_ if individual functions could have their own metatable.  It
would make for a more polymorphic way of doing things. For instance,
in PL the functions creating sequences return functions, so that they
are immediately consumable by for loops, etc.  To chain methods
operating on sequences, it's necessary to create a wrapper object
explicitly.  Now this wrapper object defines __call appropriately, so
the result is still callable ('functors'). This tends to be the
recommended practice, but one takes a performance hit for this.

Metatables for individual functions would allow method chains
operating on functions. So the question is, what are the performance
implications of such a feature?

steve d.