add support of deep raw
This commit is contained in:
parent
a45e0eee22
commit
828f2a3b8b
2 changed files with 13 additions and 1 deletions
10
lib.nix
10
lib.nix
|
@ -22,8 +22,16 @@ let
|
||||||
|
|
||||||
warn = msg: builtins.trace "[nix2lua] warning: ${msg}";
|
warn = msg: builtins.trace "[nix2lua] warning: ${msg}";
|
||||||
|
|
||||||
mkLuaRaw = raw: { _type = "raw"; inherit raw; };
|
|
||||||
isLuaRaw = expr: getType expr == "raw";
|
isLuaRaw = expr: getType expr == "raw";
|
||||||
|
mkLuaRaw = expr:
|
||||||
|
if isLuaRaw expr then
|
||||||
|
{ _type = "raw"; raw = expr.raw; }
|
||||||
|
else if isString expr || isLuaRaw expr then
|
||||||
|
{ _type = "raw"; raw = expr; }
|
||||||
|
else
|
||||||
|
error "Value '${toString expr}' is not supported for a raw type";
|
||||||
|
|
||||||
|
# mkCall = fnName: args: mkLuaRaw
|
||||||
|
|
||||||
LuaNil = { _type = "nil"; };
|
LuaNil = { _type = "nil"; };
|
||||||
isLuaNil = expr: getType expr == "nil";
|
isLuaNil = expr: getType expr == "nil";
|
||||||
|
|
|
@ -108,6 +108,10 @@ pkgs.lib.runTests {
|
||||||
expr = toLua (mkLuaRaw "hello");
|
expr = toLua (mkLuaRaw "hello");
|
||||||
expected = "hello";
|
expected = "hello";
|
||||||
};
|
};
|
||||||
|
"test returns deep raw string" = {
|
||||||
|
expr = toLua (mkLuaRaw (mkLuaRaw (mkLuaRaw "hello")));
|
||||||
|
expected = "hello";
|
||||||
|
};
|
||||||
"test returns path as string" = {
|
"test returns path as string" = {
|
||||||
expr = toLua /foo/bar;
|
expr = toLua /foo/bar;
|
||||||
expected = "\"/foo/bar\"";
|
expected = "\"/foo/bar\"";
|
||||||
|
|
Loading…
Reference in a new issue