{"id":19429780,"url":"https://github.com/chayleaf/notlua","last_synced_at":"2025-04-24T18:32:50.888Z","repository":{"id":143344659,"uuid":"615106430","full_name":"chayleaf/notlua","owner":"chayleaf","description":"A Nix DSL that compiles to Lua","archived":false,"fork":false,"pushed_at":"2024-06-10T22:28:50.000Z","size":240,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-06-12T04:57:11.642Z","etag":null,"topics":["dsl","lua","nix"],"latest_commit_sha":null,"homepage":"","language":"Nix","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/chayleaf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2023-03-17T00:53:00.000Z","updated_at":"2024-06-10T22:28:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"a944cb22-3a0b-4b79-a7af-10cd1202b014","html_url":"https://github.com/chayleaf/notlua","commit_stats":{"total_commits":61,"total_committers":1,"mean_commits":61.0,"dds":0.0,"last_synced_commit":"ef7cdb7a883fe87238c9fff13bc14ad1fd06f4ba"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chayleaf%2Fnotlua","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chayleaf%2Fnotlua/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chayleaf%2Fnotlua/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/chayleaf%2Fnotlua/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/chayleaf","download_url":"https://codeload.github.com/chayleaf/notlua/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223962621,"owners_count":17232506,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dsl","lua","nix"],"created_at":"2024-11-10T14:21:21.743Z","updated_at":"2024-11-10T14:21:22.275Z","avatar_url":"https://github.com/chayleaf.png","language":"Nix","readme":"# Not Lua\n\nEver wanted to write Lua programs in... not Lua? Well, you're in the\nright place! Now you can also write them in Nix!\n\nFeatures:\n- TYPE SYSTEM (well, only those types that can be checked are checked)\n- it accidentally looks like lisp\n- first-class Neovim support\n- that's about it?\n\nLimitations:\n- poor error messages?\n- you lose currying compared to Nix (please don't try it, you're bound\n  to fail)\n\nSimple examples: see [checks](./checks.nix).\n\nComplex examples: see [my neovim\nconfig](https://github.com/chayleaf/dotfiles/blob/master/home/common/nvim.nix)\n\nSee also: [notnft](https://github.com/chayleaf/notnft) (nftables\nrule DSL for Nix)\n\n## Try it out\n\nCheck out [sample.nix](./sample.nix) (you can run it with\n`./sample.nix` after cloning this repository). To immediately feed the\ncompiled code to Lua, do `./sample.nix | lua` (assuming you have Lua\nin your `PATH` of course).\n\nTo use this in your config, add this flake's output\n`nixosModules.default` to your NixOS module list and then access it via\n`config.notlua` or the module argument `notlua`. Alternatively, use this\nflake's output `lib.${system}`.\n\n## Overview\n\n`notlua.utils` contains various functions, out of which you should only\nreally care about `compile`. It takes a module name (which will be used\nto prefix variables, so you can put multiple modules in a single .lua\nfile), and the statements to compile to lua. The other functions are\ninternal functions mostly only useful for macro developers.\n\nThere are many keywords provided. You can choose your preferred keyword\ncase by using `notlua.screamingKeywords` (`KEYWORD_NAME`),\n`notlua.pascalKeywords` (`KeywordName`) or `notlua.camelKeywords`\n(`keywordName`). Below, the list of keywords in `screamingKeywords` is\nprovided, which is the default and also available via `notlua.keywords`:\n\n- `RAW \u003ccode\u003e`: escape raw Lua code (Use `ERAW` or `SRAW` to hint that\n  it's a statement/expression)\n- `PROP \u003cexpression\u003e \u003cname\u003e`: get a property of `\u003cexpression\u003e` with a\n  name `\u003cname\u003e` (must be a string)\n- `UNSAFE_PROP`: same, but don't throw an error if expression isn't a\n  table\n- `CALL \u003cexpr\u003e [\u003cexprs\u003e...]`: call a function. Arguments are variadic,\n  i.e. if you want to call `print(1, 2)` you do `CALL print 1 2`.\n- `UNSAFE_CALL`: same, but don't check function arity (argument count)\n- `APPLY`: apply a list of arguments to a function (so you can do `APPLY\n  (CALL print) [1 2]`)\n- `MCALL`: call a method (`table:method()`). First argument is the\n  table, second is method name, other arguments are passed to the\n  function.\n- `SET \u003cvar/vars\u003e \u003cexprs...\u003e`: sets something to something (the `=`\n  statement). You can pass multiple values:\n  - to assign to multiple lhs (`a, b = c`), use a list as lhs\n    (`SET [a b] c`)\n  - to assign multiple rhs (`a = b, c`), pass the rhs as varargs\n    (`SET a b c`)\n  - you can combine them (`a, b = b, a` -\u003e `SET [a b] b a`)\n- `UNSAFE_SET`: same, but don't throw an error if type doesn't match or\n  if lhs isn't a valid lhs\n- `LEN`: length operator\n- `NOT`: not operator\n- `UNM`: unary minus\n- `EQ` `GE` `LE` `GT` `LT` `NE` `AND` `OR` - logical operators\n- `ADD` `SUB` `MUL` `DIV` - arithmetic operators\n- `CAT` - concat operator\n- All binary operators take a variable amount of arguments, just like\n  functions!\n- There's probably many more operators you can add via `OP2` (`OP2 \"==\"`\n  is the same as `EQ`, etc)\n- `FORIN` - iterate over an iterator with a callback (first argument:\n  iterator, second argument: callback).\n  Example: `FORIN (CALL pairs table) (k: v: CALL print k v)`\n- `FORRANGE` - Lua's numeric for\n- `WHILE` - while loop\n- `REPEAT` - repeat loop\n- `RETURN` - return an expression (or just return, or return multiple\n  expressions)\n- `BREAK` - break statement\n- `DEFUN` - create a zero argument function with provided body.\n- `DEFUN_VAR` - create a function with a variable argument count. The\n  varargs will be passed as the last parameter.\n- `IF` - if condition. Syntax: `IF \u003ccond1\u003e \u003cbranch1\u003e \u003ccond2\u003e \u003cbranch2\u003e\n  \u003cfallback branch\u003e`, or `IF \u003ccond1\u003e \u003cbranch1\u003e \u003ccond2\u003e \u003cbranch2\u003e ELSE\n  \u003cfallback branch\u003e` (those are equivalent)\n- `IDX` - dynamically get a table's value (the `[]` operator)\n- `UNSAFE_IDX` - same, but don't throw an error if it isn't a table.\n- `LET` - create a local variable and call a callback with it.\n  Example: `LET 1 2 3 (one: two: three: CALL print (ADD one two))`\n- `LETREC`: same, but instead of expressions you provide functions that\n  take the variables and generate the expressions. Example: the fifth\n  fibonacci number:\n  ```lua\n  LETREC\n    (fib:\n      (n:\n        IF (LT n 2)\n          (RETURN n)\n        ELSE\n          (RETURN (ADD (fib (SUB n 1)) (fib (SUB n 2))))))\n    (fib: CALL print (fib 5))\n  ```\n- `MERGE`: merge two table-like values in Nix (can be lists or\n  attrsets). If you do that, use `ATTR_PART` to get only the attrs of a\n  table and `LIST_PART` to get only the list part.\n- `MACRO`, `MACRO'`: the entire compiler is built on macros! In fact,\n  the only keyword that isn't a macro is `MACRO` (for obvious reasons).\n  Macros are functions that take transpiler state and return raw\n  compiled code. There are also `LMACRO`s (short for \"let macro\") for\n  creating custom variants of `LET`. For more info on macros, see\n  [INTERNALS](./INTERNALS.md).\n\nAdditionally, statement lists compile to one statement per line,\nexpression lists and attrsets compile to tables. Functions compile to\nfunction expressions. You can even pass functions with attrset\nparameters to the compiler: `({ a, b, c }: d: CALL print a b c d)` will\nresult in:\n\n```lua\nfunction(arg1, arg2)\n  print(arg1.a, arg1.b, arg1.c, arg2)\nend\n```\n\nThere are autogenerated bindings for convenient interaction with Lua or\nNeovim. They are available at `notlua.neovim { neovim-unwrapped,\nplugins, extraLuaPackages }` and `notlua.lua { lua }` (all attributes\nare optional). It exposes two modules - `stdlib` and `keywords`.\n`stdlib` contains the default functions (such as `print` and `require`),\nand `keywords` provides `REQ` (a version of `stdlib.require` that also\nautogenerates bindings) and `REQ'` (same, but it executes not just\nrequires, but arbitrary code, which can generate wrong bindings if you\nuse it the wrong way, be careful).\n\nNote that this means you don't have to do `CALL print a b` like I wrote\nabove, just `print a b` is enough! However, if a function has zero\narguments, or if you want to call a table, you will still have to use\n`CALL` (or even `UNSAFE_CALL`).\n\nThe bindings are type-aware and will not let you call a function with a\nwrong argument count or set a Vim option to a wrong type (or any\nother module's value, for that matter). That is, unless you use the\nunsafe versions of the methods.\n\n## License\n\nGPL 3 or later - you're free to use this in FOSS projects, or in\nprojects which you use privately.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchayleaf%2Fnotlua","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fchayleaf%2Fnotlua","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fchayleaf%2Fnotlua/lists"}