[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Functions with individual metatables
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 19 May 2009 08:33:19 +0200
On Mon, May 18, 2009 at 7:27 PM, Duncan Cross <firstname.lastname@example.org> wrote:
> Another way I think it could be useful is where you need to "tag"
> certain functions - for example, say you have an __index metamethod
> that looks up the key in a hidden table containing both ordinary
> method functions, and "property-getter" functions - the former should
> be returned normally, but the latter should immediately be called,
> passing in "self" as a parameter. A metatable would let you quickly
> tell what kind of function you have and take the right course of
> action. (Two tables is the obvious solution for achieving this right
> now, but it obviously requires an extra table lookup, at least some of
> the time.)
There's a lot of cool things that can be done. For instance, you can
make tostring() return a sensible string; you can keep track of where
a function came from in a debugger, etc. Tagging functions could have
a lot of interesting applications.
(Making string metatables individual however strikes me as dim. You're
going to be carrying that extra pointer for every damn little string,
and I can't think of any problem that couldn't be solved by a table
I shall do a few experiments:
- with current global function metatable, are there any nasty suprises?
- look at source, see what the minimal change is, and do benchmarks
on common things like method dispatch. From what I've seen, it would
require another case statement in the metatable lookup.