Skip to content

Commit

Permalink
Merge pull request #226 from horriblename/fix-lua-null-conversion
Browse files Browse the repository at this point in the history
Fix lua null conversion
  • Loading branch information
NotAShelf authored Feb 17, 2024
2 parents 2b17496 + a57e89d commit cd4d0cd
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/lua.nix
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -80,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 "";
else throw "could not convert object of type `${typeOf args}` to lua object";
}

0 comments on commit cd4d0cd

Please sign in to comment.