Skip to content

Commit 160e3c5

Browse files
ffrostfallaatxe
andauthored
Fix net.serve not being yieldable (#219)
Fixes #169 by deriving a lua_State from the runtime global lua_State, and then resuming it with the handler function. --------- Co-authored-by: ariel <[email protected]>
1 parent 9657d02 commit 160e3c5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/src/net.cpp

+3-2
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ static void processRequest(
237237
const std::string_view& body
238238
)
239239
{
240-
lua_State* L = state->runtime->GL;
240+
lua_State* L = lua_newthread(state->runtime->GL);
241241

242242
lua_createtable(L, 0, 5);
243243

@@ -266,7 +266,8 @@ static void processRequest(
266266
lua_pushvalue(L, -2);
267267
lua_remove(L, -3);
268268

269-
if (lua_pcall(L, 1, 1, 0) != 0)
269+
int status = lua_resume(L, nullptr, 1);
270+
if (status != LUA_OK && status != LUA_YIELD)
270271
{
271272
std::string error = lua_tostring(L, -1);
272273
lua_pop(L, 1);

0 commit comments

Comments
 (0)