[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: [LuaJIT] C-API Question on meta table for C closure
- From: Stefan Behnel <stefan_ml@...>
- Date: Fri, 03 Sep 2010 09:49:56 +0200
when I set a metatable on a C closure, it seems to spread to all Lua
functions, not only to the specific closure at hand. The code I use is
objtype* obj = (objtype*)lua_newuserdata(L, sizeof(objtype))
lua_pushcclosure(L, <lua.lua_CFunction>asfunc_call, 1)
I'm just setting the metatable on both the user data object and the closure
so that both behave as expected when handled separately. In particular, I
need to supply indexing callbacks for both, but I also use other meta
methods like "__tostring".
After that, when I declare a new (regular) function in Lua code and call
tostring() on it, it calls into the metatable of the above closure. 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?