fix lambda
This commit is contained in:
parent
ce62a78f5a
commit
adc3641605
2 changed files with 16 additions and 1 deletions
13
lib.nix
13
lib.nix
|
@ -138,7 +138,18 @@ let
|
|||
++ [ kw_end ])
|
||||
);
|
||||
func0 = fnName: func fnName [ ];
|
||||
lambda = func "";
|
||||
|
||||
lambda = params: body:
|
||||
(spaceBetween
|
||||
([
|
||||
(concat [
|
||||
kw_function
|
||||
(wrapParen (join ", " (map raw params)))
|
||||
])
|
||||
]
|
||||
++ (validBlockBody body)
|
||||
++ [ kw_end ])
|
||||
);
|
||||
lambda0 = lambda [ ];
|
||||
|
||||
return = expr: spaceBetween ([ kw_return expr ]);
|
||||
|
|
|
@ -173,6 +173,10 @@ with nix2lua; pkgs.lib.runTests {
|
|||
expr = toLua (func "hello" [ "a" ] (call1 "h.world" (var "a")));
|
||||
expected = "function hello(a) h.world(a) end";
|
||||
};
|
||||
"test returns defined lambda" = {
|
||||
expr = toLua (lambda [ "a" ] (call1 "h.world" (var "a")));
|
||||
expected = "function(a) h.world(a) end";
|
||||
};
|
||||
"test returns if statement" = {
|
||||
expr = toLua (if' (eq 10 10) (call "print" [ 10 ]));
|
||||
expected = ''if (10 == 10) then print(10) end'';
|
||||
|
|
Loading…
Reference in a new issue