lua-users home
lua-l archive

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

2009/3/25 Mark Hamburg <>:
> Is there any reason not to support metatables for functions? Obviously the
> __call metamethod is superfluous for functions, but I could imagine uses for
> other cases. In particular, one could then consider using operators to
> combine functions. Since these cases would currently just end in an error or
> in the generic metatable for functions and given that functions aren't
> particularly tiny objects to begin with, the cost seems like it ought to be
> small.
> I'll have to think about whether this would be truly useful or just
> interesting, but I was wondering whether there is a reason why it would be a
> bad idea.

You can implement pseudo-functions with userdata and a __call
metamethod. You then have all other meta-method accessible (and
overriding type to return 'function' is trivial).

But of course you would need some C code to do that, which is
unfortunate. It would be nice to have a mechanism to create userdata
from Lua (something like an official newproxy).