[Date Prev][Date Next][Thread Prev][Thread Next]
- 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, and "per
function metatables" would allow a better syntax for their methods and
One of the ways to define objects in Lua is using only functions.
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
Although perhaps more theoretical than practical,  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.
 PiL 2nd, 16.5 "The Single Method Approach"