diff --git a/lib.nix b/lib.nix index 72e0baf..9383803 100644 --- a/lib.nix +++ b/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 ]); diff --git a/lib.test.nix b/lib.test.nix index 8731185..69e9832 100644 --- a/lib.test.nix +++ b/lib.test.nix @@ -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'';