mirror of
https://github.com/luanti-org/luanti.git
synced 2025-07-02 16:38:41 +00:00
Implement vector and node conversion in Lua (#12609)
Co-authored-by: sfan5 <sfan5@live.de>
This commit is contained in:
parent
23e9f5db43
commit
b38ffdec27
29 changed files with 191 additions and 167 deletions
|
@ -10,3 +10,4 @@ dofile(commonpath .. "chatcommands.lua")
|
|||
dofile(clientpath .. "chatcommands.lua")
|
||||
dofile(clientpath .. "death_formspec.lua")
|
||||
dofile(clientpath .. "misc.lua")
|
||||
assert(loadfile(commonpath .. "item_s.lua"))({}) -- Just for push/read node functions
|
||||
|
|
|
@ -223,3 +223,17 @@ function builtin_shared.cache_content_ids()
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
if core.set_read_node and core.set_push_node then
|
||||
local function read_node(node)
|
||||
return name2content[node.name], node.param1, node.param2
|
||||
end
|
||||
core.set_read_node(read_node)
|
||||
core.set_read_node = nil
|
||||
|
||||
local function push_node(content, param1, param2)
|
||||
return {name = content2name[content], param1 = param1, param2 = param2}
|
||||
end
|
||||
core.set_push_node(push_node)
|
||||
core.set_push_node = nil
|
||||
end
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
_G.core = {}
|
||||
_G.vector = {metatable = {}}
|
||||
dofile("builtin/common/vector.lua")
|
||||
dofile("builtin/common/misc_helpers.lua")
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
_G.core = {}
|
||||
_G.vector = {metatable = {}}
|
||||
|
||||
_G.setfenv = require 'busted.compatibility'.setfenv
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
_G.vector = {metatable = {}}
|
||||
_G.vector = {}
|
||||
dofile("builtin/common/vector.lua")
|
||||
|
||||
describe("vector", function()
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
_G.core = {get_once = function(_) end}
|
||||
_G.vector = {metatable = {}}
|
||||
_G.unpack = table.unpack
|
||||
_G.serverlistmgr = {}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue