From 95566f10fba984eca53813fc8ad2f813dd76ed45 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 17 Feb 2024 16:44:05 +0100 Subject: [PATCH 1/3] fix: expToLua convert null to nil --- lib/lua.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/lua.nix b/lib/lua.nix index 55e22d3..e37db7a 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -19,6 +19,8 @@ in rec { then lib.boolToString exp # if bool, convert to string else if builtins.isInt exp then builtins.toString exp # if int, convert to string + else if exp == null + then "nil" else (builtins.toJSON exp); # otherwise jsonify the value and print as is # convert list to a lua table From 40b985c066227b5237d6506e070cc5dc91ff1b90 Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 17 Feb 2024 16:44:41 +0100 Subject: [PATCH 2/3] fix: bug where toLuaObject converts null to "" --- lib/lua.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/lua.nix b/lib/lua.nix index e37db7a..4bd4930 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -82,7 +82,7 @@ in rec { then "${toString args}" else if builtins.isInt args then "${toString args}" - else if (args != null) + else if (args == null) then "nil" else ""; } From a57e89dece266c95e3de16311661efbcd8dfe1ab Mon Sep 17 00:00:00 2001 From: Ching Pei Yang Date: Sat, 17 Feb 2024 21:55:07 +0100 Subject: [PATCH 3/3] fix: throw error when converting unknown object to lua --- lib/lua.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/lua.nix b/lib/lua.nix index 4bd4930..708b464 100644 --- a/lib/lua.nix +++ b/lib/lua.nix @@ -1,7 +1,7 @@ # Helpers for converting values to lua {lib}: let inherit (lib) mapAttrsToList filterAttrs concatStringsSep concatMapStringsSep stringToCharacters boolToString; - inherit (builtins) hasAttr head; + inherit (builtins) hasAttr head throw typeOf; in rec { # Convert a null value to lua's nil nullString = value: @@ -84,5 +84,5 @@ in rec { then "${toString args}" else if (args == null) then "nil" - else ""; + else throw "could not convert object of type `${typeOf args}` to lua object"; }