From 6279ccc7a8ee6ab200ca2ae5c50cfc8cde14af73 Mon Sep 17 00:00:00 2001 From: Emik Date: Fri, 13 Feb 2026 22:31:25 +0100 Subject: [PATCH] Improve versatility of the 'f' export --- src/functional.lua | 19 ++++++++++++++++++- src/seal.lua | 8 ++------ 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/functional.lua b/src/functional.lua index 8221839..b8ae0b4 100644 --- a/src/functional.lua +++ b/src/functional.lua @@ -66,8 +66,25 @@ local _ = luaf._proto ---@param f_pairs? fun(t: table): unknown ---@param numeric boolean? ---@return Query +---@overload fun(obj: true): (fun(): true) +---@overload fun(obj: false): (fun(): false) +---@overload fun(obj: string): (fun(any): any) local function f(obj, f_pairs, numeric) - return f_pairs and luaf.from(obj, f_pairs, numeric ~= false) or (obj[1] and luaf.ipairs(obj) or luaf.pairs(obj)) + if obj == true then + return luaf.tru + elseif obj == false then + return luaf.fals + elseif type(obj) == "string" then + return luaf.index(obj) + elseif type(obj) ~= "table" then + error("Invalid argument type for f's obj: " .. type(obj)) + elseif f_pairs then + return luaf.from(obj, f_pairs, numeric ~= false) + elseif obj[#obj] then + return luaf.ipairs(obj) + else + return luaf.pairs(obj) + end end --- Queues an event to be run. diff --git a/src/seal.lua b/src/seal.lua index b2c02d5..897859f 100644 --- a/src/seal.lua +++ b/src/seal.lua @@ -23,12 +23,8 @@ SMODS.Seal { local tag = Tag(get_next_tag_key "Roland_glass") if tag.name == "Orbital Tag" then - tag.ability.orbital_hand = pseudorandom_element( - f(G.GAME.hands):filter(function(v) - return v.visible - end):keys():into(), - pseudoseed "Roland_glass" - ) + local hands = f(G.GAME.hands):filter(f "visible"):keys():into() + tag.ability.orbital_hand = pseudorandom_element(hands, pseudoseed "Roland_glass") end add_tag(tag)