[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Operators on functions
- From: "John Hind" <john.hind@...>
- Date: Tue, 19 Nov 2013 09:58:07 -0000
That is a good idea! At present the per-type metatables are held in the State (with a reserved slot for each type, oddly including slots for table and userdata which are never used).
How about a scheme analogous to the metamethods in the metatable ("__index" etc.) but in the environment table: there would be reserved keys for each type "__number", "__function" etc. containing, if present, the per-type metatable. Slightly less efficient in execution, but more memory efficient and more flexible.
Also, would it be useful to have per-value metatables on function type in the same way as for table and userdata?
Finally, I refer you to my powerpatch in the WiKi allowing table and userdata to have per-type metamethods in addition to per-value ones. The per-type metatable acts like a default which is overridden by any per-value assignment. This allows, for example, methods to be assigned automatically to tables in the same way as they currently are to strings. This would be much more flexible in conjunction with holding per-type metatables in the environment.
> Date: Tue, 19 Nov 2013 08:17:34 +0200
> From: steve donovan <firstname.lastname@example.org>
> Subject: Re: Operators on functions
> Now, if the shared metatable of functions was relative to _ENV, then
> we could have the situation that a person could organize things to
> their satisfaction within their modules, without trampling on the
> design space of other modules.