Skip to content

Commit

Permalink
Ability to remove minetest.after once set (#10103)
Browse files Browse the repository at this point in the history
  • Loading branch information
tenplus1 committed Sep 23, 2020
1 parent add6836 commit 34e3ede
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
6 changes: 4 additions & 2 deletions builtin/common/after.lua
Expand Up @@ -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
5 changes: 4 additions & 1 deletion doc/lua_api.txt
Expand Up @@ -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
------

Expand Down

0 comments on commit 34e3ede

Please sign in to comment.