diff --git a/README.md b/README.md index a3871bd..116939b 100644 --- a/README.md +++ b/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` diff --git a/lib.nix b/lib.nix index d332d34..d6949e3 100644 --- a/lib.nix +++ b/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] @@ -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;