NixLazy.nvim/lib.nix

25 lines
743 B
Nix
Raw Normal View History

2023-09-15 13:35:56 +02:00
{ lib, ... }:
with lib;
rec {
toLua = value: with builtins;
if value == null then "nil" else
if isBool value then boolToString value else
if isInt value || isFloat value then toString value else
if isString value then string value else
if isAttrs value then attrs value else
if isList value then list value else
abort "should never happen (value = ${value})";
string = str: ''"${toString str}"'';
attrs = set:
let
toKeyword = name: value: "['${name}'] = ${toLua value}";
keywords = concatStringsSep ", " (mapAttrsToList toKeyword set);
in
"{ " + keywords + " }";
listContent = values: concatStringsSep ", " (map toLua values);
list = values: "{ " + listContent values + " }";
}