2023-04-17 23:01:45 +00:00
|
|
|
# Helpers for converting values to lua
|
2023-06-04 11:12:08 +00:00
|
|
|
{lib}: rec {
|
|
|
|
# yes? no.
|
2023-04-17 23:01:45 +00:00
|
|
|
yesNo = value:
|
|
|
|
if value
|
|
|
|
then "yes"
|
|
|
|
else "no";
|
|
|
|
|
2023-06-04 11:12:08 +00:00
|
|
|
# Convert a null value to lua's nil
|
2023-04-17 23:01:45 +00:00
|
|
|
nullString = value:
|
|
|
|
if value == null
|
|
|
|
then "nil"
|
|
|
|
else "'${value}'";
|
2023-06-04 11:12:08 +00:00
|
|
|
|
2023-06-05 18:37:12 +00:00
|
|
|
# convert an expression to lua
|
2023-06-04 14:36:01 +00:00
|
|
|
expToLua = exp:
|
|
|
|
if builtins.isList exp
|
|
|
|
then listToLuaTable exp
|
|
|
|
else if builtins.isAttrs exp
|
|
|
|
then attrsetToLuaTable exp
|
|
|
|
else ("\"" + builtins.toJSON exp + "\"");
|
|
|
|
|
2023-06-05 18:37:12 +00:00
|
|
|
# convert list to a lua table
|
2023-06-04 14:36:01 +00:00
|
|
|
listToLuaTable = list:
|
|
|
|
"{ " + (builtins.concatStringsSep ", " (map expToLua list)) + " }";
|
2023-06-04 11:12:08 +00:00
|
|
|
|
2023-06-05 18:37:12 +00:00
|
|
|
# convert attrset to a lua table
|
2023-06-04 11:12:08 +00:00
|
|
|
attrsetToLuaTable = attrset:
|
|
|
|
"{ "
|
|
|
|
+ (
|
|
|
|
builtins.concatStringsSep ", "
|
2023-06-04 14:36:01 +00:00
|
|
|
(
|
|
|
|
lib.mapAttrsToList (
|
2023-06-04 11:12:08 +00:00
|
|
|
name: value:
|
2023-06-04 14:36:01 +00:00
|
|
|
name
|
|
|
|
+ " = "
|
|
|
|
+ (expToLua value)
|
2023-06-04 11:12:08 +00:00
|
|
|
)
|
|
|
|
attrset
|
2023-06-04 14:36:01 +00:00
|
|
|
)
|
2023-06-04 11:12:08 +00:00
|
|
|
)
|
|
|
|
+ " }";
|
2023-04-17 23:01:45 +00:00
|
|
|
}
|