diff --git a/builtin/common/after.lua b/builtin/common/after.lua index b314711c9..e20f292f0 100644 --- a/builtin/common/after.lua +++ b/builtin/common/after.lua @@ -31,11 +31,13 @@ function core.after(after, func, ...) assert(tonumber(after) and type(func) == "function", "Invalid minetest.after invocation") local expire = time + after - jobs[#jobs + 1] = { + local new_job = { func = func, expire = expire, arg = {...}, - mod_origin = core.get_last_run_mod() + mod_origin = core.get_last_run_mod(), } + jobs[#jobs + 1] = new_job time_next = math.min(time_next, expire) + return { cancel = function() new_job.func = function() end end } end diff --git a/doc/lua_api.txt b/doc/lua_api.txt index a1baadf6d..bd845aad3 100644 --- a/doc/lua_api.txt +++ b/doc/lua_api.txt @@ -5336,10 +5336,13 @@ Sounds Timing ------ -* `minetest.after(time, func, ...)` +* `minetest.after(time, func, ...)` : returns job table to use as below. * Call the function `func` after `time` seconds, may be fractional * Optional: Variable number of arguments that are passed to `func` +* `job:cancel()` + * Cancels the job function from being called + Server ------