My problem is that lua_pcall clears the stack, because i want to reuse the stack before the call again with just one change again.
Is there a way to either copy the complete stack and paste it in again or even a way to call a lua function without clearing the stack?
Lua:
function test(a)
print(a)
end
event.add("test", test)
event.add("test", test)
event.call("test", 42)
C++:
int Func_Event_call(Lua_State* L){
//Stack: String:Eventname, Arguments...
std::string name = luaL_checkstring(L, 1);
... Get array functions from name
for(...){
//load function into stack
lua_rawgeti(L, LUA_REGISTRYINDEX, functions[c]);
lua_replace(L, 1);
//Wanted Stack: Lua_Function, Arguments... <- works for the first function
//call function
lua_pcall(L, nummberArgs, 0, 0);
//stack is now empty because of lua_pcall <- problem
}
return 0;
}
I solved the problem by using a table in the registry and put the complete stack in the table with numeric keys. After calling the second part i can go back to the stack when the first part was called, but multiple times.