neovim-flake/lib/lua.nix

41 lines
795 B
Nix
Raw Normal View History

# Helpers for converting values to lua
{lib}: rec {
# yes? no.
yesNo = value:
if value
then "yes"
else "no";
# Convert a null value to lua's nil
nullString = value:
if value == null
then "nil"
else "'${value}'";
2023-06-04 16:36:01 +02:00
expToLua = exp:
if builtins.isList exp
then listToLuaTable exp
else if builtins.isAttrs exp
then attrsetToLuaTable exp
else ("\"" + builtins.toJSON exp + "\"");
listToLuaTable = list:
"{ " + (builtins.concatStringsSep ", " (map expToLua list)) + " }";
attrsetToLuaTable = attrset:
"{ "
+ (
builtins.concatStringsSep ", "
2023-06-04 16:36:01 +02:00
(
lib.mapAttrsToList (
name: value:
2023-06-04 16:36:01 +02:00
name
+ " = "
+ (expToLua value)
)
attrset
2023-06-04 16:36:01 +02:00
)
)
+ " }";
}