Refactor, cleanup

This commit is contained in:
Zef Hemel
2025-06-12 20:30:01 +02:00
parent b942ebabad
commit 8d3dc4cc4e
120 changed files with 1139 additions and 1101 deletions
+39
View File
@@ -0,0 +1,39 @@
local function assertEqual(a, b, message)
if a ~= b then
error("Assertion failed: " .. a .. " is not equal to " .. b .. " " .. message)
end
end
lume = lume or {}
local getiter = function(x)
if lume.isarray(x) then
return ipairs
elseif type(x) == "table" then
return pairs
end
error("expected table", 3)
end
function lume.isarray(x)
return type(x) == "table" and x[1] ~= nil
end
function lume.concat(...)
local rtn = {}
for i = 1, select("#", ...) do
local t = select(i, ...)
if t ~= nil then
local iter = getiter(t)
for _, v in iter(t) do
rtn[#rtn + 1] = v
end
end
end
return rtn
end
local r = lume.concat({1, 2}, {3, 4})
assertEqual(#r, 4)
assertEqual(r[1], 1)
assertEqual(r[4], 4)