mirror of
https://github.com/NotAShelf/nvf.git
synced 2025-04-15 00:58:37 +00:00
lib/lua: deprecate old Lua helpers superseded by toLuaObject
This commit is contained in:
parent
028bdc522c
commit
dade4b6ed6
1 changed files with 9 additions and 39 deletions
48
lib/lua.nix
48
lib/lua.nix
|
@ -1,8 +1,8 @@
|
||||||
# Helpers for converting values to lua
|
# Helpers for converting values to lua
|
||||||
{lib}: let
|
{lib}: let
|
||||||
inherit (builtins) hasAttr head throw typeOf isList isAttrs isBool isInt isString isPath isFloat toJSON;
|
inherit (builtins) head throw typeOf isList isAttrs isBool isInt isString isPath isFloat toJSON;
|
||||||
inherit (lib.attrsets) mapAttrsToList filterAttrs;
|
inherit (lib.attrsets) mapAttrsToList filterAttrs hasAttr;
|
||||||
inherit (lib.strings) concatStringsSep concatMapStringsSep stringToCharacters concatLines;
|
inherit (lib.strings) concatStringsSep concatMapStringsSep stringToCharacters;
|
||||||
inherit (lib.trivial) boolToString warn;
|
inherit (lib.trivial) boolToString warn;
|
||||||
in rec {
|
in rec {
|
||||||
# Convert a null value to lua's nil
|
# Convert a null value to lua's nil
|
||||||
|
@ -11,43 +11,13 @@ in rec {
|
||||||
then "nil"
|
then "nil"
|
||||||
else "'${value}'";
|
else "'${value}'";
|
||||||
|
|
||||||
# convert an expression to lua
|
expToLua = exp: builtins.warn "expToLua is deprecated, please use toLuaObject instead" (toLuaObject exp);
|
||||||
expToLua = exp:
|
listToLuaTable = exp: builtins.warn "listToLuaTable is deprecated, please use toLuaObject instead" (toLuaObject exp);
|
||||||
if isList exp
|
attrsetToLuaTable = exp: builtins.warn "attrsetToLuaTable is deprecated, please use toLuaObject instead" (toLuaObject exp);
|
||||||
then listToLuaTable exp # if list, convert to lua table
|
luaTable = exp: builtins.warn "luaTable is deprecated, please use toLuaObject instead" (toLuaObject exp);
|
||||||
else if isAttrs exp
|
|
||||||
then attrsetToLuaTable exp # if attrs, convert to table
|
|
||||||
else if isBool exp
|
|
||||||
then boolToString exp # if bool, convert to string
|
|
||||||
else if isInt exp
|
|
||||||
then toString exp # if int, convert to string
|
|
||||||
else if exp == null
|
|
||||||
then "nil"
|
|
||||||
else (toJSON exp); # otherwise jsonify the value and print as is
|
|
||||||
|
|
||||||
# convert list to a lua table
|
|
||||||
listToLuaTable = list:
|
|
||||||
"{ " + (concatStringsSep ", " (map expToLua list)) + " }";
|
|
||||||
|
|
||||||
# convert attrset to a lua table
|
|
||||||
attrsetToLuaTable = attrset:
|
|
||||||
"{ "
|
|
||||||
+ (
|
|
||||||
concatStringsSep ", "
|
|
||||||
(
|
|
||||||
mapAttrsToList (
|
|
||||||
name: value:
|
|
||||||
name
|
|
||||||
+ " = "
|
|
||||||
+ (expToLua value)
|
|
||||||
)
|
|
||||||
attrset
|
|
||||||
)
|
|
||||||
)
|
|
||||||
+ " }";
|
|
||||||
# Convert a list of lua expressions to a lua table. The difference to listToLuaTable is that the elements here are expected to be lua expressions already, whereas listToLuaTable converts from nix types to lua first
|
|
||||||
luaTable = items: ''{${concatStringsSep "," items}}'';
|
|
||||||
|
|
||||||
|
# Check if the given object is a Lua inline object.
|
||||||
|
# isLuaInline :: AttrSet -> Bool
|
||||||
isLuaInline = object: (object._type or null) == "lua-inline";
|
isLuaInline = object: (object._type or null) == "lua-inline";
|
||||||
|
|
||||||
toLuaObject = args:
|
toLuaObject = args:
|
||||||
|
|
Loading…
Add table
Reference in a new issue