From b1ee724a9cbe3a7376ef3b630c88c73f7a47312a Mon Sep 17 00:00:00 2001 From: AstroSnail Date: Wed, 8 Jan 2025 08:12:40 +0000 Subject: [PATCH] Improve map and set value constructors they can now take arguments to add to the value immediately --- terms-generators.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/terms-generators.lua b/terms-generators.lua index 2962247..4e8ee33 100644 --- a/terms-generators.lua +++ b/terms-generators.lua @@ -326,11 +326,15 @@ end ---@field default_print fun(MapValue, ...) local map_type_mt = { - __call = function(self) + __call = function(self, ...) local val = { _map = {}, } setmetatable(val, self) + local args = table.pack(...) + for i = 1, args.n, 2 do + val:set(args[i], args[i + 1]) + end return val end, __eq = function(left, right) @@ -475,11 +479,15 @@ define_map = U.memoize(define_map) ---@field default_print fun(SetValue, ...) local set_type_mt = { - __call = function(self) + __call = function(self, ...) local val = { _set = {}, } setmetatable(val, self) + local args = table.pack(...) + for i = 1, args.n do + val:put(args[i]) + end return val end, __eq = function(left, right)