[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Functions with individual metatables
- From: steve donovan <steve.j.donovan@...>
- Date: Tue, 19 May 2009 09:42:31 +0200
On Tue, May 19, 2009 at 9:34 AM, Richard Hundt <richardhundt@gmail.com> wrote:
> function setmetatable(that, meta)
> if type(that) == "function" then
> return setfmeta(that, meta)
> end
> return setmeta(that, meta)
> end
>
> function getmetatable(that)
> if type(that) == "function" then
> return getfmeta(that)
> end
> return getmeta(that)
> end
That is indeed clever! But would not give us the ability to give
arbitrary functions attributes in a seamless way.
> fmeta = {}
> fmeta.__index = fmeta
> fmeta.attrb = 'hello'
> debug.setmetatable(math.sin,fmeta)
> return math.sin.attrb
hello
> return math.cos.attrb
hello
>
They all have the same attribute, which is probably not useful. Hence
the need for individual metatables.
steve d.