lib: add RFC-145 nixdoc comments to extended library functions

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I41c4b2cb70512699a044578fa88eb8266a6a6964
This commit is contained in:
raf 2026-05-20 17:02:36 +03:00
commit a17f043605
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
7 changed files with 506 additions and 19 deletions

View file

@ -1,7 +1,57 @@
# Helpers for converting values to lua
{lib}: let
/**
Test whether an object is a `luaInline` value (i.e. has `_type == "lua-inline"`).
# Type
```
isLuaInline :: Any -> Bool
```
# Arguments
- `object`: Any Nix value.
# Example
```nix
isLuaInline (lib.mkLuaInline "vim.fn.getcwd()")
=> true
isLuaInline "just a string"
=> false
```
*/
isLuaInline = object: (object._type or null) == "lua-inline";
/**
Recursively convert a Nix value to its Lua representation as a string.
Handles all primitive Nix types as well as lists, attribute sets,
derivations (rendered as their store path string), and `luaInline` values
(rendered verbatim). Null attributes are stripped from sets.
# Type
```
toLuaObject :: Any -> String
```
# Arguments
- `args`: Any Nix value to convert.
# Example
```nix
toLuaObject { a = 1; b = true; c = null; }
=> ''{["a"] = 1,\n["b"] = true}''
toLuaObject [ "x" "y" ]
=> ''{"x",\n"y"}''
```
*/
toLuaObject = args:
{
int = toString args;
@ -42,6 +92,30 @@
in
{
inherit isLuaInline toLuaObject;
/**
Convert a list of Lua expression strings into a Lua table string.
Each element is wrapped with `mkLuaInline` before conversion so that
strings are treated as raw Lua rather than quoted string literals.
# Type
```
luaTable :: [String] -> String
```
# Arguments
- `x`: List of Lua expression strings.
# Example
```nix
luaTable [ "vim.fn.getcwd()" "vim.fn.expand('%')" ]
=> ''{vim.fn.getcwd(),\nvim.fn.expand('%')}''
```
*/
luaTable = x: (toLuaObject (map lib.mkLuaInline x));
}
// lib.genAttrs [