From 1f2ceab526a5492160c8fec83cc8308d1d9994ee Mon Sep 17 00:00:00 2001 From: Sviatoslav Abakumov Date: Mon, 11 Mar 2024 22:22:11 +0400 Subject: [PATCH] Allow passing nil as name to hs.pasteboard.callbackWhenChanged 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