调用Lua函数引起C++崩溃

我使用下面的代码从C++调用Lua函数,但有时会崩溃。

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

我的代码有什么问题吗?

点赞