mazda7
mazda7

Reputation: 31

LuaBind c++ error handler when calling a Lua function

I am little newbie in C++ scripting but I know some things. I'm compiling a plugin that use a function to call an Lua callback using the LuaBind, but the client crashes when function doesn't exists on main.lua, also I'm trying to add an error handler to that functions... I don't know what I can do to solve it.

Here is my code:

{
    try
    {
        luabind::call_function<int>(L, "onServerFrame", elapsedTime);
    }
    catch (luabind::error& e)
    {
        std::string error = lua_tostring(e.state(), -1);
        std::cout << error << "\n";
    }
}

Upvotes: 2

Views: 195

Answers (1)

mazda7
mazda7

Reputation: 31

Solved. Thanks to my friend habi.

luabind::object func = g[name]; 
if( func ) { if( luabind::type(func) == LUA_TFUNCTION ) luabind::call_function<void>(L,"onServerFrame", elapsedTime);}

Upvotes: 1

Related Questions