I use the following code to call Lua function from C++ but it crashes sometimes.
void callLuaFunction(lua_State *L, const char *name)
{
if (L == nullptr) return;
lua_getglobal(L, name);
if (lua_type(L, -1) != LUA_TFUNCTION)
return;
if (lua_pcall(L, 0, 0, 0))
error("%s", lua_tostring(L, -1));
}
Is there anything wrong with my code?