[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metatables for functions
- From: Jerome Vuarand <jerome.vuarand@...>
- Date: Wed, 25 Mar 2009 02:01:06 +0100
2009/3/25 Mark Hamburg <email@example.com>:
> 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
> 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).