fix(lua): stack overflow in signal
This commit is contained in:
parent
18b12ea1ad
commit
778a5e35a4
2 changed files with 13 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
#include "datatypes/base.h"
|
||||
#include "meta.h"
|
||||
#include "lua.h"
|
||||
#include <luajit-2.1/lua.h>
|
||||
#include <pugixml.hpp>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
@ -30,7 +31,15 @@ LuaSignalConnection::~LuaSignalConnection() {
|
|||
luaL_unref(state, LUA_REGISTRYINDEX, function);
|
||||
}
|
||||
|
||||
static void stackdump(lua_State* L) {
|
||||
for (int i = lua_gettop(L); i >= 1; i--) {
|
||||
printf("Obj: %s\n", lua_typename(L, lua_type(L, i)));
|
||||
}
|
||||
printf("\n\n");
|
||||
}
|
||||
|
||||
void LuaSignalConnection::Call(std::vector<Data::Variant> args) {
|
||||
// stackdump(state);
|
||||
lua_State* thread = lua_newthread(state);
|
||||
|
||||
// Push function
|
||||
|
@ -45,6 +54,8 @@ void LuaSignalConnection::Call(std::vector<Data::Variant> args) {
|
|||
Logger::error(lua_tostring(thread, -1));
|
||||
lua_pop(thread, 1); // Pop return value
|
||||
}
|
||||
|
||||
lua_pop(state, 1); // Pop thread
|
||||
}
|
||||
|
||||
//
|
||||
|
|
|
@ -117,6 +117,8 @@ int script_delay(lua_State* L) {
|
|||
luaL_checktype(L, 2, LUA_TFUNCTION);
|
||||
|
||||
lua_State* Lt = lua_newthread(L); // Create a new thread
|
||||
// I think this is memory abuse??
|
||||
// Wouldn't popping the thread in this case make it eligible for garbage collection?
|
||||
lua_pop(L, 1); // pop the newly created thread so that xmove moves func instead of it into itself
|
||||
lua_xmove(L, Lt, 1); // move func
|
||||
lua_pop(L, 1); // pop secs
|
||||
|
|
Loading…
Add table
Reference in a new issue