doc: update readme

This commit is contained in:
Dmitriy Pleshevskiy 2024-05-17 18:45:29 +03:00
parent 958fe9e674
commit 6ec872969f
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 33 additions and 2 deletions

View file

@ -285,6 +285,38 @@ Add `nix2lua` as input to your `flake.nix`
> # local function foo(bar) bar.baz() end > # 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 # License
GNU General Public License v3.0 or later GNU General Public License v3.0 or later

View file

@ -152,8 +152,7 @@ let
lambda0 = lambda [ ]; lambda0 = lambda [ ];
return = expr: spaceBetween ([ kw_return expr ]); return = expr: spaceBetween ([ kw_return expr ]);
return_void = return return_void = return null;
null;
ifelse = condition: trueBody: falseBody: ifelse = condition: trueBody: falseBody:
(spaceBetween (concatLists [ (spaceBetween (concatLists [