add aliases for set and func

lset = local . set
lfunc = local . func
lfunc0 = local . func0
This commit is contained in:
Dmitriy Pleshevskiy 2024-05-17 18:38:57 +03:00
parent d02b3b0fcc
commit 958fe9e674
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
2 changed files with 19 additions and 4 deletions

View file

@ -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`

13
lib.nix
View file

@ -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]
@ -223,15 +224,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;