trumanzhao/luna

当pcall失败,return false前没有把errstring 和debug.traceback pop出来,会导致栈溢出。

Closed this issue · 1 comments

当pcall失败,return false前没有把errstring 和debug.traceback pop出来,会导致栈溢出。

bool lua_call_function(lua_State* L, std::string* err, int arg_count, int ret_count) {
    int func_idx = lua_gettop(L) - arg_count;
    if (func_idx <= 0 || !lua_isfunction(L, func_idx))
        return false;
    lua_getglobal(L, "debug");
    lua_getfield(L, -1, "traceback");
    lua_remove(L, -2); // remove 'debug'
    lua_insert(L, func_idx);
    if (lua_pcall(L, arg_count, ret_count, func_idx)) {
        if (err != nullptr) {
            *err = lua_tostring(L, -1);
        }
        return false;
    }
    lua_remove(L, -ret_count - 1); // remove 'traceback'
    return true;
}

已修正