2022-06-14 01:11:20 +02:00
|
|
|
stairsplus.util = {
|
|
|
|
table_set_all = function(t, other_table)
|
|
|
|
for key, value in pairs(other_table) do
|
|
|
|
t[key] = value
|
|
|
|
end
|
|
|
|
return t
|
2022-06-14 20:17:06 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
table_is_empty = function(t)
|
|
|
|
return not next(t)
|
|
|
|
end,
|
|
|
|
|
|
|
|
table_sort_keys = function(t, sort_function)
|
|
|
|
local sorted = {}
|
|
|
|
for key in pairs(t) do
|
|
|
|
table.insert(sorted, key)
|
|
|
|
end
|
|
|
|
if sort_function then
|
|
|
|
table.sort(sorted, sort_function)
|
|
|
|
else
|
|
|
|
table.sort(sorted)
|
|
|
|
end
|
|
|
|
return sorted
|
2022-06-17 21:22:47 +02:00
|
|
|
end,
|
|
|
|
|
|
|
|
check_call = function(func)
|
|
|
|
-- wrap a function w/ logic to avoid crashing the game
|
|
|
|
local f = function(...)
|
|
|
|
local status, out = pcall(func, ...)
|
|
|
|
if status then
|
|
|
|
return out
|
|
|
|
else
|
|
|
|
local message = ("Error (func): %s %s"):format(out, dump({...}))
|
|
|
|
stairsplus.log("error", message)
|
|
|
|
error(message)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return f
|
2022-06-14 01:11:20 +02:00
|
|
|
end
|
|
|
|
}
|