Fixed stack issue with lEvents

This commit is contained in:
CPunch 2021-05-09 00:58:10 -05:00 committed by gsemaj
parent a29de394ee
commit aa3dacc84b

View File

@ -189,6 +189,11 @@ public:
switch (event->type) { switch (event->type) {
case EVENT_CALLBACK: { case EVENT_CALLBACK: {
// make thread for this callback // make thread for this callback
if (!lua_checkstack(event->state, 1)) {
std::cout << "[FATAL] Failed to create new lua thread! out of memory!" << std::endl;
terminate(0);
}
lua_State *nThread = lua_newthread(event->state); lua_State *nThread = lua_newthread(event->state);
// push the callable first, the push all the arguments // push the callable first, the push all the arguments
@ -197,9 +202,6 @@ public:
// then call it :) // then call it :)
yieldCall(nThread, nargs); yieldCall(nThread, nargs);
// we can safely pop the thread off the stack now
lua_pop(event->state, 1);
break; break;
} }
case EVENT_WAIT: { case EVENT_WAIT: {