From 3e815df4996bf2baa91697466223fdff1fce0af4 Mon Sep 17 00:00:00 2001 From: Sviatoslav Abakumov Date: Mon, 5 Aug 2024 18:38:05 +0400 Subject: [PATCH] Allow passing nil as name to hs.pasteboard.callbackWhenChanged (#3616) The issue was that calling `hs.pasteboard.callbackWhenChanged(nil, 1, function() end)` raised "callback must be a function". This is because ipairs stops iterating the varargs table on the first nil element, so the for-loop body is not executed. --- extensions/pasteboard/pasteboard.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/extensions/pasteboard/pasteboard.lua b/extensions/pasteboard/pasteboard.lua index 95be76586..152651386 100644 --- a/extensions/pasteboard/pasteboard.lua +++ b/extensions/pasteboard/pasteboard.lua @@ -88,7 +88,9 @@ end --- ~~~ module.callbackWhenChanged = function(...) local name, timeout, callback = nil, 2.0, nil - for _, v in ipairs({...}) do + local args = {...} + for i = 1, #args do + local v = args[i] if type(v) == "number" then timeout = v elseif type(v) == "nil" or type(v) == "string" then