Question

I have some code using Luabind, and I need to execute a function (from C++) if it's present in the _G table, but otherwise do nothing. How do I detect if a function is present in _G or not?

Was it helpful?

Solution

Something like this should work:

if (luabind::object f = luabind::globals(L)["f"])
{
    f(...);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top