2023-04-18 01:01:45 +02:00
|
|
|
# Helpers for converting values to lua
|
2023-06-04 13:12:08 +02:00
|
|
|
{lib}: rec {
|
|
|
|
# yes? no.
|
2023-04-18 01:01:45 +02:00
|
|
|
yesNo = value:
|
|
|
|
if value
|
|
|
|
then "yes"
|
|
|
|
else "no";
|
|
|
|
|
2023-06-04 13:12:08 +02:00
|
|
|
# Convert a null value to lua's nil
|
2023-04-18 01:01:45 +02:00
|
|
|
nullString = value:
|
|
|
|
if value == null
|
|
|
|
then "nil"
|
|
|
|
else "'${value}'";
|
2023-06-04 13:12:08 +02:00
|
|
|
|
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)) + " }";
|
2023-06-04 13:12:08 +02:00
|
|
|
|
|
|
|
attrsetToLuaTable = attrset:
|
|
|
|
"{ "
|
|
|
|
+ (
|
|
|
|
builtins.concatStringsSep ", "
|
2023-06-04 16:36:01 +02:00
|
|
|
(
|
|
|
|
lib.mapAttrsToList (
|
2023-06-04 13:12:08 +02:00
|
|
|
name: value:
|
2023-06-04 16:36:01 +02:00
|
|
|
name
|
|
|
|
+ " = "
|
|
|
|
+ (expToLua value)
|
2023-06-04 13:12:08 +02:00
|
|
|
)
|
|
|
|
attrset
|
2023-06-04 16:36:01 +02:00
|
|
|
)
|
2023-06-04 13:12:08 +02:00
|
|
|
)
|
|
|
|
+ " }";
|
2023-04-18 01:01:45 +02:00
|
|
|
}
|