25 lines
743 B
Nix
25 lines
743 B
Nix
|
{ 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 + " }";
|
||
|
}
|