From 9666618527a63e79ccc1855beeab285cd8480727 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 19 Nov 2022 00:25:30 +0300 Subject: [PATCH] add mkLuaRaw method --- lib.nix | 6 +++++- lib.test.nix | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/lib.nix b/lib.nix index 2d450d5..63170b3 100644 --- a/lib.nix +++ b/lib.nix @@ -2,6 +2,9 @@ let inherit (builtins) isString isFloat isInt isBool isList isAttrs isNull; inherit (builtins) concatStringsSep filter mapAttrs attrValues; + mkLuaRaw = raw: { _type = "raw"; inherit raw; }; + isLuaRaw = val: getType val == "raw"; + mkLuaNil = { _type = "nil"; }; isLuaNil = val: getType val == "nil"; @@ -17,6 +20,7 @@ let toLua = val: if isLuaNil val then "nil" + else if isLuaRaw val then val.raw else if isDictItem val then toLuaDictItem val.name val.value else if isAttrs val then toLuaDict val else if isList val then toLuaList val @@ -47,5 +51,5 @@ let in { inherit toLua; - inherit mkLuaNil mkDictItem; + inherit mkLuaNil mkDictItem mkLuaRaw; } diff --git a/lib.test.nix b/lib.test.nix index f9f94d4..3dbcb48 100644 --- a/lib.test.nix +++ b/lib.test.nix @@ -2,7 +2,7 @@ let nix2lua = import ./lib.nix; - inherit (nix2lua) toLua mkLuaNil mkDictItem; + inherit (nix2lua) toLua mkLuaNil mkDictItem mkLuaRaw; in pkgs.lib.runTests { "test returns null" = { @@ -77,4 +77,8 @@ pkgs.lib.runTests { ]; expected = "{ \"foo\", [\"foo\"] = \"hello\", 10 }"; }; + "test returns raw string" = { + expr = toLua (mkLuaRaw "hello"); + expected = "hello"; + }; }