Add table.nilget

This commit is contained in:
Lars Mueller 2020-12-12 15:55:09 +01:00
parent 7a30cc06dd
commit 9f5de0d3a6

@ -15,6 +15,21 @@ function set_case_insensitive_index(table)
return map_index(table, string.lower) return map_index(table, string.lower)
end end
function nilget(table, key, ...)
assert(key ~= nil)
local function nilget(table, key, ...)
if key == nil then
return table
end
local value = table[key]
if value == nil then
return nil
end
return nilget(value, ...)
end
return nilget(table, key, ...)
end
-- Fisher-Yates -- Fisher-Yates
function shuffle(table) function shuffle(table)
for index = 1, #table - 1 do for index = 1, #table - 1 do