diff --git a/builtin/game/async.lua b/builtin/game/async.lua index d184440c9..f85864649 100644 --- a/builtin/game/async.lua +++ b/builtin/game/async.lua @@ -34,7 +34,7 @@ if core.async_job_methods then local dummy = function() end function core.async_job_methods:cancel() - return self:get_id() == self:replace(dummy, dummy) + return self:get_id() == self:replace(dummy, dummy):get_id() end core.async_job_methods = nil diff --git a/games/devtest/mods/unittests/async_env.lua b/games/devtest/mods/unittests/async_env.lua index fb081614c..7d222c148 100644 --- a/games/devtest/mods/unittests/async_env.lua +++ b/games/devtest/mods/unittests/async_env.lua @@ -212,7 +212,6 @@ local function test_async_job_replacement(cb) local job = core.handle_async(function(x) return x end, function(ret) - print(ret) cb("Replaced async callback still run") end, 1) local newjob = job:replace(function(x) @@ -223,7 +222,7 @@ local function test_async_job_replacement(cb) end end, 2) if job:get_id() ~= newjob:get_id() then - cb("core.replace_async sanity check failed") + cb("AsyncJob:replace sanity check failed") end job = core.handle_async(function(x) @@ -243,7 +242,7 @@ local function test_async_job_replacement(cb) return cb("Wrong async value passed to old handler") end - newjob = job:replace(id, function(x) + newjob = job:replace(function(x) return -x end, function(new_ret) if new_ret ~= -2 then @@ -252,10 +251,10 @@ local function test_async_job_replacement(cb) cb() end, 2) if job:get_id() == newjob:get_id() then - cb("core.replace_async replaced a completed job") + cb("AsyncJob:replace replaced a completed job") end - if id:cancel() then - cb("core.relpace_async canceled a completed job") + if job:cancel() then + cb("AsyncJob:replace canceled a completed job") end end, 1) end diff --git a/src/script/lua_api/l_async.cpp b/src/script/lua_api/l_async.cpp index 8c0e52f8f..e2c8ec7be 100644 --- a/src/script/lua_api/l_async.cpp +++ b/src/script/lua_api/l_async.cpp @@ -77,7 +77,7 @@ void LuaAsyncJob::Register(lua_State *L) lua_getglobal(L, "core"); luaL_getmetatable(L, className); lua_getfield(L, -1, "__index"); - lua_setfield(L, -2, "async_job_methods"); + lua_setfield(L, -3, "async_job_methods"); } const char LuaAsyncJob::className[] = "AsyncJob";