diff --git a/README.md b/README.md index 116939b..bffd538 100644 --- a/README.md +++ b/README.md @@ -285,6 +285,38 @@ Add `nix2lua` as input to your `flake.nix` > # local function foo(bar) bar.baz() end > ``` +`return expr` + +> Return expression from a function. +> +> ```nix +> toLua (func "foo" ["bar"] (return (pipe1 "bar" "baz")); +> # function foo(bar) return bar.baz end +> ``` +> +> Useful aliases: +> ``` +> return_void = return null; +> ``` + +`ifelse condition trueBody falseBody` + +> Make a Lua if else statement. +> +> ```nix +> toLua (ifelse (eq 10 10) (call "print" "yes") (call "print" "no")); +> # if (10 == 10) print("yes") else print("no") end +> ``` + +`if' condition trueBody` + +> Make a Lua if statement without else. +> +> ```nix +> toLua (if' (eq 10 10) (call "print" "yes")); +> # if (10 == 10) print("yes") end +> ``` + # License GNU General Public License v3.0 or later diff --git a/lib.nix b/lib.nix index d6949e3..c038ebb 100644 --- a/lib.nix +++ b/lib.nix @@ -152,8 +152,7 @@ let lambda0 = lambda [ ]; return = expr: spaceBetween ([ kw_return expr ]); - return_void = return - null; + return_void = return null; ifelse = condition: trueBody: falseBody: (spaceBetween (concatLists [