Compare commits
2 commits
d02b3b0fcc
...
6ec872969f
Author | SHA1 | Date | |
---|---|---|---|
6ec872969f | |||
958fe9e674 |
2 changed files with 52 additions and 6 deletions
42
README.md
42
README.md
|
@ -219,7 +219,7 @@ Add `nix2lua` as input to your `flake.nix`
|
|||
> lte = op "<=";
|
||||
>
|
||||
> and = op kw_and;
|
||||
> or = op kw_or;
|
||||
> or' = op kw_or;
|
||||
> not = expr: spaceBetween [ kw_not expr ];
|
||||
> ```
|
||||
|
||||
|
@ -231,6 +231,11 @@ Add `nix2lua` as input to your `flake.nix`
|
|||
> toLua (set "vim.opt.number" true);
|
||||
> # vim.opt.number = true
|
||||
> ```
|
||||
>
|
||||
> Useful aliases:
|
||||
> ```
|
||||
> lset = l: r: local (set l r);
|
||||
> ```
|
||||
|
||||
`func fnName params body`
|
||||
|
||||
|
@ -244,6 +249,9 @@ Add `nix2lua` as input to your `flake.nix`
|
|||
> Useful aliases:
|
||||
> ```
|
||||
> func0 = fnName: func fnName [ ];
|
||||
>
|
||||
> lfunc = n: p: b: local (func n p b);
|
||||
> lfunc0 = n: b: local (func0 n b);
|
||||
> ```
|
||||
|
||||
`lambda params body`
|
||||
|
@ -277,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
|
||||
|
|
16
lib.nix
16
lib.nix
|
@ -79,6 +79,7 @@ let
|
|||
call0 = fnName: call fnName [ ];
|
||||
call1 = fnName: arg: call fnName [ arg ];
|
||||
require = name: call "require" name;
|
||||
requireTo = name: local (set (require name));
|
||||
|
||||
kw_and = raw "and";
|
||||
kw_or = raw "or";
|
||||
|
@ -115,7 +116,7 @@ let
|
|||
lte = op "<=";
|
||||
|
||||
and = op kw_and;
|
||||
or = op kw_or;
|
||||
or' = op kw_or;
|
||||
not = expr: spaceBetween [ kw_not expr ];
|
||||
|
||||
# Type: validBlockBody :: a -> [b]
|
||||
|
@ -151,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 [
|
||||
|
@ -223,15 +223,21 @@ in
|
|||
inherit raw join concat spaceBetween;
|
||||
inherit pipe pipe1;
|
||||
|
||||
inherit namedField require local set ifelse if';
|
||||
inherit namedField local;
|
||||
inherit ifelse if';
|
||||
inherit set;
|
||||
lset = l: r: local (set l r);
|
||||
|
||||
inherit require requireTo;
|
||||
inherit call call0 call1;
|
||||
inherit func func0 lambda lambda0;
|
||||
lfunc = n: p: b: local (func n p b);
|
||||
lfunc0 = n: b: local (func0 n b);
|
||||
|
||||
inherit op;
|
||||
inherit eq ne gt lt gte lte;
|
||||
inherit add sub mul div mod exp;
|
||||
inherit and or not;
|
||||
inherit and or' not;
|
||||
|
||||
inherit return return_void;
|
||||
|
||||
|
|
Loading…
Reference in a new issue