From 44d24e549da92b56e7551caa3974bc603cfdcf53 Mon Sep 17 00:00:00 2001 From: whosit Date: Wed, 11 Dec 2024 17:23:24 +0300 Subject: [PATCH] better handle cases when "nothing" is returned --- init.lua | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/init.lua b/init.lua index 596facb..838d177 100644 --- a/init.lua +++ b/init.lua @@ -153,8 +153,12 @@ core.register_chatcommand("eval", local n = select("#", ...) local res = {...} ok = res[1] - -- API calls can sometimes return literal "nothing", so `n` can be 1 - if n <= 2 then + if n == 1 then + -- In some cases, calling a function can return literal "nothing": + -- + Executing loadstring(`x = 1`) returns "nothing". + -- + API calls also can sometimes return literal "nothing" instead of nil + return ok and "Done." or "Failed without error message." + elseif n == 2 then -- returned single value or error env._ = res[2] -- store result in "_" per-user "global" variable if ok then