diff options
author | Jude Melton-Houghton <jwmhjwmh@gmail.com> | 2022-10-18 18:01:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-18 18:01:44 -0400 |
commit | b38ffdec279bcded98e34f5116c8d676aa9f73a7 (patch) | |
tree | 31cafdb009b2f81b61a96286a3800a8e408f8f3d /builtin/common/vector.lua | |
parent | 23e9f5db4330a6efee5270160a3959422926ce77 (diff) | |
download | minetest-b38ffdec279bcded98e34f5116c8d676aa9f73a7.tar.xz |
Implement vector and node conversion in Lua (#12609)
Co-authored-by: sfan5 <sfan5@live.de>
Diffstat (limited to 'builtin/common/vector.lua')
-rw-r--r-- | builtin/common/vector.lua | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/builtin/common/vector.lua b/builtin/common/vector.lua index a08472e32..cebc99580 100644 --- a/builtin/common/vector.lua +++ b/builtin/common/vector.lua @@ -6,8 +6,10 @@ Note: The vector.*-functions must be able to accept old vectors that had no meta -- localize functions local setmetatable = setmetatable --- vector.metatable is set by C++. -local metatable = vector.metatable +vector = {} + +local metatable = {} +vector.metatable = metatable local xyz = {"x", "y", "z"} @@ -366,3 +368,22 @@ function vector.dir_to_rotation(forward, up) end return rot end + +if rawget(_G, "core") and core.set_read_vector and core.set_push_vector then + local function read_vector(v) + return v.x, v.y, v.z + end + core.set_read_vector(read_vector) + core.set_read_vector = nil + + if rawget(_G, "jit") then + -- This is necessary to prevent trace aborts. + local function push_vector(x, y, z) + return (fast_new(x, y, z)) + end + core.set_push_vector(push_vector) + else + core.set_push_vector(fast_new) + end + core.set_push_vector = nil +end |