diff --git a/lib.nix b/lib.nix index 46f4c6e..9f58a6c 100644 --- a/lib.nix +++ b/lib.nix @@ -16,7 +16,7 @@ */ let inherit (builtins) isString isFloat isInt isBool isList isAttrs isNull isPath; - inherit (builtins) concatStringsSep filter mapAttrs attrValues concatLists; + inherit (builtins) concatStringsSep filter mapAttrs attrValues concatLists match; isNotNull = v: !(isNull v); excludeNull = expr: filter isNotNull expr; @@ -175,7 +175,10 @@ let toLuaBool = expr: if expr then "true" else "false"; toLuaNumber = toString; - toLuaString = expr: "\"${validString expr}\""; + toLuaString = expr: + let str = validString expr; in + let isLines = match ".*\n.*" str; in + if isLines != null then "[[\n${str}]]" else "\"${str}\""; toLuaList = onValue: expr: let wrapObj = expr: "{ ${concatStringsSep ", " expr} }"; diff --git a/lib.test.nix b/lib.test.nix index 3543aca..7262265 100644 --- a/lib.test.nix +++ b/lib.test.nix @@ -35,6 +35,17 @@ with nix2lua; pkgs.lib.runTests { expr = toLua "hello world"; expected = ''"hello world"''; }; + "test returns a multiline lua string" = { + expr = toLua '' + hello + world + ''; + expected = '' + [[ + hello + world + ]]''; + }; "test returns a path as a lua string" = { expr = toLua /hello/world; expected = ''"/hello/world"'';