LuaBind c++调用Lua函数时的错误处理

我是一个 C++ 脚本新手,但我知道一些东西。 我正在编译一个使用函数调用 Lua 回调的插件,使用 LuaBind 时,当函数在 main.lua 上不存在时,客户端崩溃了,我正在尝试添加一个错误处理程序到这些函数中... 我不知道该怎么解决它。

以下是我的代码:

{
    try
    {
        luabind::call_function<int>(L, "onServerFrame", elapsedTime);
    }
    catch (luabind::error& e)
    {
        std::string error = lua_tostring(e.state(), -1);
        std::cout << error << "\n";
    }
}
点赞
用户14316331
用户14316331
```cpp
luabind::object func = g[name];
if (func) {
    if (luabind::type(func) == LUA_TFUNCTION) {
        luabind::call_function<void>(L, "onServerFrame", elapsedTime);
    }
}

```

我的朋友 habi 帮我解决了。

2020-09-22 13:15:31