[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Metatables for functions
- From: David Manura <dm.lua@...>
- Date: Wed, 25 Mar 2009 21:33:29 -0400
On Wed, Mar 25, 2009 at 10:26 AM, Mark Hamburg wrote:
>>> Is there any reason not to support metatables for functions?
> I should perhaps have been more precise and said "per function metatables"
> (defaulting back to a shared metatable for compatibility).
Functions provide a convenient implementation of tuples[1], and "per
function metatables" would allow a better syntax for their methods and
operators.
One of the ways to define objects in Lua is using only functions[2].
It has a simplicity/generality not available in the table/metatable
approach, but it lacks some in syntax (a la Lisp), so it is not often
used. Maybe "per function metatables" would somehow change this
though.
Although perhaps more theoretical than practical, [3] demonstrates how
Lua closures can reimplement the semantics of Lua tables. By using
debug.setmetatable on these functions (ideally with "per function
metatables"), they can obtain the same syntax as well.
[1] http://lua-users.org/wiki/FunctionalTuples
[2] PiL 2nd, 16.5 "The Single Method Approach"
[3] http://lua-users.org/wiki/MutableFunctions