split table funtions into their own mod
parent
113cd7db41
commit
7cde2d24d9
|
@ -4,3 +4,6 @@
|
|||
[submodule "mods/lambda"]
|
||||
path = mods/lambda
|
||||
url = https://gitlab.com/benrob0329/lua-lambda.git
|
||||
[submodule "mods/table_goodies"]
|
||||
path = mods/table_goodies
|
||||
url = https://gitlab.com/benrob0329/lua-table_goodies
|
||||
|
|
|
@ -80,63 +80,6 @@ do -- Nodes --
|
|||
})
|
||||
end
|
||||
|
||||
do -- Extra stdlib functions --
|
||||
local function half_equals(t1, t2)
|
||||
for k, v in pairs(t1) do
|
||||
if t2[k] == nil then
|
||||
return false
|
||||
elseif type(v) == "table" then
|
||||
if (v ~= t1) and (not half_equals(t2[k], v)) then
|
||||
return false
|
||||
end
|
||||
elseif not (t2[k] == v) then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
function table.equals(t1, t2)
|
||||
return half_equals(t1, t2) and half_equals(t2, t1)
|
||||
end
|
||||
|
||||
function table.merge(t1, t2, ...)
|
||||
if ... then
|
||||
local ts = { t2, ... }
|
||||
for i = 1, #ts do
|
||||
for k, v in pairs(ts[i]) do
|
||||
t1[k] = v
|
||||
end
|
||||
end
|
||||
else
|
||||
for k, v in pairs(t2) do
|
||||
t1[k] = v
|
||||
end
|
||||
end
|
||||
|
||||
-- Not needed, but handy for passing t1 back to another function
|
||||
return t1
|
||||
end
|
||||
end
|
||||
|
||||
do -- Test table.equals --
|
||||
local error_message = [[
|
||||
Function %s does not pass self-test!
|
||||
Expected results: %s
|
||||
Test Results: %s
|
||||
]]
|
||||
|
||||
local test_table = { "a", "b", c = false, e = { "f", "g", "h", { "h" } } }
|
||||
table.insert(test_table, test_table)
|
||||
local results = table.equals(test_table, test_table)
|
||||
local error = error_message:format("table.equals", "true", tostring(results))
|
||||
assert(results, error)
|
||||
|
||||
local results2 = not table.equals({ a = 1 }, { a = 2 })
|
||||
local error2 = error_message:format("table.equals", "false", tostring(results2))
|
||||
assert(results2, error2)
|
||||
end
|
||||
|
||||
-- Default Nodedef Tables --
|
||||
local error_node = minetest.registered_nodes["ikea:error"]
|
||||
|
||||
|
|
|
@ -1 +1,2 @@
|
|||
name = ikea
|
||||
deps = table_goodies
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 5ee154f22395f6036386de23eaaa746aab626966
|
Loading…
Reference in New Issue