From adc3641605cc5b27bb04ff073f911d5d59bf0ce1 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Sat, 20 Apr 2024 20:12:52 +0300 Subject: [PATCH] fix lambda --- lib.nix | 13 ++++++++++++- lib.test.nix | 4 ++++ 2 files changed, 16 insertions(+), 1 deletion(-) 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'';