c++ - 调用Lua函数时的LuaBind C++错误处理程序

标签 c++ error-handling lua callback luabind

我不是C++脚本的新手,但我知道一些事情。
我正在编译一个插件,该插件使用函数使用LuaBind调用Lua回调,但是当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";
    }
}

最佳答案

解决了。感谢我的 friend 哈比。

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

关于c++ - 调用Lua函数时的LuaBind C++错误处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63997059/

相关文章:

browser - window.onerror不会捕获所有错误

离开页面时 JQuery Ajax 错误

java - 捕获可扔物的好理由是什么?

lua - 添加事件监听器 : Listener cannot be nil

lua - 从服务器接收数据时出错

c++ - C++ 基本类型的对齐方式和大小

c++ - Python GIL 和线程

xml-parsing - 使用 LuaXml 的表条目数不正确

c++ - 使用 Alpha channel 复制 SDL_Surfaces

c++ - 非法引用非静态成员或未解析的外部符号