LuaBridge icon indicating copy to clipboard operation
LuaBridge copied to clipboard

Suggestion: A way to determinate if LuaRef is callable

Open rysson opened this issue 11 years ago • 5 comments

Useful way to determinate if LuaRef is callable for functions and tables with metatable __call, for example: bool LuaRef::isCallable() const;

Now tables with metatable __call can be called by LuaRef, but is no easy way to check it has a sense (isFunction()==false, isTable()==true, as for regular table).

Access to metatable is not easy too (luaL_getmetatable?). LuaRef LuaRef::metatable() will be nice.

Thanks for your work!

rysson avatar Jan 20 '15 11:01 rysson

It's not forbidden to manipulate metatables on the C++ side (but forbidden on the Lua side). You can do the following:

luaRef.push ();
lua_getmetatable (L, -1);
auto metatable = LuaRef::fromStack (L);

and then

if (metatable ["__call"].isFunction ())
{
  luaRef (1, 2);
}

I'm just thinking whether it's worth adding a helper function like that:

luabridge::LuaRef luabridge::getMetatable (const luabridge::LuaRef& luaRef);

dmitry-t avatar Jun 06 '19 19:06 dmitry-t

Great, getMetatable looks OK. And next helper isCallable will be perfect :-)

rysson avatar Jun 07 '19 07:06 rysson

Both getMetatable and isCallable are available in https://github.com/kunitoki/LuaBridge3

kunitoki avatar Apr 17 '21 14:04 kunitoki

@kunitoki If you want to take care of the LB why don't you just ask? There are no obstacles, if your version is better, we'll just put instructions how to switch to your repo. Otherwise you can simply push your version to this repo. I'm not the owner as well, but.

dmitry-t avatar May 08 '21 20:05 dmitry-t

Will think about it.

kunitoki avatar May 08 '21 21:05 kunitoki