lua-users home
lua-l archive

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


On Fri, 2010-09-03 at 09:49 +0200, Stefan Behnel wrote:
> ... I would 
> have expected that other functions are not impacted by a metatable that I 
> set on a single C function.
> 
> Is that the expected behaviour? Is there a way to define a metatable only 
> for a specific C function?
> 

Citing the Lua manual (http://www.lua.org/manual/5.1/manual.html#2.8):

	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.

Here, "etc." also contains functions - which means that you can have
only one metatable for functions globally. If you want to have a
callable object (which acts like a function), better create a
table/userdata and use the __call metamethod.