From 5b6f9be18ccafc5b0fb6e17c4faf7c88c5eea75f Mon Sep 17 00:00:00 2001 From: y5nw <37980625+y5nw@users.noreply.github.com> Date: Tue, 18 Feb 2025 07:17:27 +0100 Subject: [PATCH] review --- games/devtest/mods/unittests/async_env.lua | 5 ++--- src/script/lua_api/l_async.cpp | 4 +++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/games/devtest/mods/unittests/async_env.lua b/games/devtest/mods/unittests/async_env.lua index fd8443bea..dc595ef88 100644 --- a/games/devtest/mods/unittests/async_env.lua +++ b/games/devtest/mods/unittests/async_env.lua @@ -209,14 +209,14 @@ end unittests.register("test_async_vector", test_vector_preserve, {async=true}) local function test_async_job_replacement(cb) + core.ipc_set("unittests:end_blocking", nil) local capacity = core.get_async_threading_capacity() for _ = 1, capacity do core.handle_async(function() core.ipc_poll("unittests:end_blocking", 1000) end, function() end) end - local job = core.handle_async(function(x) - return x + local job = core.handle_async(function() end, function() return cb("Canceled async job run") end) @@ -229,7 +229,6 @@ local function test_async_job_replacement(cb) job = core.handle_async(function(x) return x end, function(ret) - core.ipc_set("unittests:end_blocking", nil) if job:cancel() then return cb("AsyncJob:cancel canceled a completed job") end diff --git a/src/script/lua_api/l_async.cpp b/src/script/lua_api/l_async.cpp index 773d8e918..6291e9f8d 100644 --- a/src/script/lua_api/l_async.cpp +++ b/src/script/lua_api/l_async.cpp @@ -11,7 +11,9 @@ static std::string get_serialized_function(lua_State *L, int index) call_string_dump(L, index); size_t func_length; const char *serialized_func_raw = lua_tolstring(L, -1, &func_length); - return std::string(serialized_func_raw, func_length); + std::string serialized_func(serialized_func_raw, func_length); + lua_pop(L, 1); + return serialized_func; } // do_async_callback(func, params, mod_origin)