From 28e87ce9d5fdf163c1eb0daf83279e949f84765d Mon Sep 17 00:00:00 2001 From: DS Date: Sat, 29 Aug 2020 17:41:29 +0200 Subject: Add vector.offset (#10321) --- builtin/common/tests/vector_spec.lua | 4 ++++ builtin/common/vector.lua | 6 ++++++ 2 files changed, 10 insertions(+) (limited to 'builtin/common') diff --git a/builtin/common/tests/vector_spec.lua b/builtin/common/tests/vector_spec.lua index 6f308a4a8..0f287363a 100644 --- a/builtin/common/tests/vector_spec.lua +++ b/builtin/common/tests/vector_spec.lua @@ -44,6 +44,10 @@ describe("vector", function() assert.same({ x = 2, y = 4, z = 6 }, vector.add(vector.new(1, 2, 3), { x = 1, y = 2, z = 3 })) end) + it("offset()", function() + assert.same({ x = 41, y = 52, z = 63 }, vector.offset(vector.new(1, 2, 3), 40, 50, 60)) + end) + -- This function is needed because of floating point imprecision. local function almost_equal(a, b) if type(a) == "number" then diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index 1fd784ce2..d6437deda 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -137,6 +137,12 @@ function vector.divide(a, b) end end +function vector.offset(v, x, y, z) + return {x = v.x + x, + y = v.y + y, + z = v.z + z} +end + function vector.sort(a, b) return {x = math.min(a.x, b.x), y = math.min(a.y, b.y), z = math.min(a.z, b.z)}, {x = math.max(a.x, b.x), y = math.max(a.y, b.y), z = math.max(a.z, b.z)} -- cgit v1.2.3 From 34e3ede8eeb05e193e64ba3d055fc67959d87d86 Mon Sep 17 00:00:00 2001 From: tenplus1 Date: Wed, 23 Sep 2020 18:11:56 +0100 Subject: Ability to remove minetest.after once set (#10103) --- builtin/common/after.lua | 6 ++++-- doc/lua_api.txt | 5 ++++- 2 files changed, 8 insertions(+), 3 deletions(-) (limited to 'builtin/common') 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 ------ -- cgit v1.2.3