简体   繁体   English

调用 Lua 时的 LuaBind c++ 错误处理程序 function

[英]LuaBind c++ error handler when calling a Lua function

I am little newbie in C++ scripting but I know some things.我是 C++ 脚本的小新手,但我知道一些事情。 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.我正在编译一个插件,它使用 function 使用 LuaBind 调用 Lua 回调,但是当 function 在main.lua上不存在时客户端崩溃,我也在尝试向该函数添加一个错误处理程序......我不知道我能做些什么来解决它。

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";
    }
}

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);}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM