2020-12-31 18:15:19 +00:00
|
|
|
{ lib, ... }:
|
2021-01-02 16:53:38 +00:00
|
|
|
with lib;
|
|
|
|
rec {
|
2020-12-31 18:15:19 +00:00
|
|
|
# vim dictionaries are, in theory, compatible with JSON
|
2021-01-02 16:53:38 +00:00
|
|
|
toVimDict = args: toJSON
|
|
|
|
(lib.filterAttrs (n: v: !isNull v) args);
|
|
|
|
|
|
|
|
# Black functional magic that converts a bunch of different Nix types to their
|
|
|
|
# lua equivalents!
|
|
|
|
toLuaObject = args:
|
|
|
|
if builtins.isAttrs args then
|
|
|
|
"{" + (concatStringsSep ","
|
|
|
|
(mapAttrsToList
|
|
|
|
(n: v: "[${toLuaObject n}] = " + (toLuaObject v))
|
|
|
|
args)) + "}"
|
|
|
|
else if builtins.isList args then
|
|
|
|
"{" + concatMapStringsSep "," toLuaObject args + "}"
|
|
|
|
else if builtins.isString args then
|
|
|
|
# This should be enough!
|
|
|
|
escapeShellArg args
|
|
|
|
else if builtins.isBool args then
|
|
|
|
"${ boolToString args }"
|
|
|
|
else if builtins.isFloat args then
|
|
|
|
"${ toString args }"
|
|
|
|
else if builtins.isInt args then
|
|
|
|
"${ toString args }"
|
|
|
|
else if isNull args then
|
|
|
|
"nil"
|
|
|
|
else "";
|
2020-12-31 18:15:19 +00:00
|
|
|
}
|