lua-users home
lua-l archive

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


Op So., 2 Sep. 2018 om 04:16 het Sean Conner <sean@conman.org> geskryf:
> It was thus said that the Great Alejandro Reimondo once stated:
> > As I know, Functions do not share a standard metatable,
> > and we can´t apply the same mechanism to extend semantics  of functions.

>>From the Lua Reference Manual:
~~~
Every value in Lua can have a metatable.
...
Tables and full userdata have individual metatables (although multiple
tables and userdata can share their metatables). Values of all other
types share one single metatable per type; that is, there is one
single metatable for all numbers, one for all strings, etc. By
default, a value has no metatable, but the string library sets a
metatable for the string type (see §6.4).
...
debug.setmetatable (value, table)

Sets the metatable for the given value to the given table (which can
be nil). Returns value.
~~~
Read together, this says that you can set a metatable for a function,
and that it will then apply to all functions.

> In a quick experiment:
> ...
> It seems that setting the metatable on one function set the metatable on all
> functions, so it appears that functions share the same metatable.

Confirming what the manual says.