From 9f5de0d3a6c74a2321787b61dc94b5c343f57274 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sat, 12 Dec 2020 15:55:09 +0100 Subject: [PATCH] Add table.nilget --- table.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/table.lua b/table.lua index dbf056a..3c485b8 100644 --- a/table.lua +++ b/table.lua @@ -15,6 +15,21 @@ function set_case_insensitive_index(table) return map_index(table, string.lower) 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 function shuffle(table) for index = 1, #table - 1 do