[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: Metatables for functions
- From: Mark Hamburg <mark@...>
- Date: Wed, 25 Mar 2009 07:26:38 -0700
On Mar 24, 2009, at 6:00 PM, Luiz Henrique de Figueiredo wrote:
Is there any reason not to support metatables for functions?
There is support for metatables for function, only not from Lua,
just from C.
Or you can use debug.setmetatable. See the example below.
__add = function(f,g) return function (...) return g(f(...)) end
function f(x) return x+1 end
function g(x) return x^2 end
Yes, but that applies the same metatable to all functions. I should
perhaps have been more precise and said "per function
metatables" (defaulting back to a shared metatable for compatibility).