From d2b6b4ec64d8eca1f6e9cd6eba3f71cee22636dd Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Thu, 20 Jan 2022 15:13:11 +0100 Subject: [PATCH] Add table.default --- table.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/table.lua b/table.lua index b5c6165..2ee2aaa 100644 --- a/table.lua +++ b/table.lua @@ -18,6 +18,14 @@ function from_iterator(...) return table end +function default(table, value) + return setmetatable(table, { + __index = function() + return value + end, + }) +end + function map_index(table, func) local mapping_metatable = { __index = function(table, key)