lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


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.