]> git.lizzy.rs Git - dragonfireclient.git/blob - builtin/game/async.lua
Merge pull request #59 from PrairieAstronomer/readme_irrlicht_change
[dragonfireclient.git] / builtin / game / async.lua
1
2 core.async_jobs = {}
3
4 function core.async_event_handler(jobid, retval)
5         local callback = core.async_jobs[jobid]
6         assert(type(callback) == "function")
7         callback(unpack(retval, 1, retval.n))
8         core.async_jobs[jobid] = nil
9 end
10
11 function core.handle_async(func, callback, ...)
12         assert(type(func) == "function" and type(callback) == "function",
13                 "Invalid minetest.handle_async invocation")
14         local args = {n = select("#", ...), ...}
15         local mod_origin = core.get_last_run_mod()
16
17         local jobid = core.do_async_callback(func, args, mod_origin)
18         core.async_jobs[jobid] = callback
19
20         return true
21 end
22