chore: rename LuaNil
This commit is contained in:
parent
222024ed3a
commit
e980b4d450
3 changed files with 17 additions and 5 deletions
|
@ -54,7 +54,7 @@ Add nix2lua as input to your flake.nix
|
||||||
> toLua mkLuaNil
|
> toLua mkLuaNil
|
||||||
> ```
|
> ```
|
||||||
|
|
||||||
`mkLuaRaw expr`
|
`LuaRaw expr`
|
||||||
|
|
||||||
> Creates a type that instructs `toLua` not to change the passed expression
|
> Creates a type that instructs `toLua` not to change the passed expression
|
||||||
> `expr`.
|
> `expr`.
|
||||||
|
|
12
lib.nix
12
lib.nix
|
@ -18,12 +18,18 @@ let
|
||||||
inherit (builtins) isString isFloat isInt isBool isList isAttrs isNull isPath;
|
inherit (builtins) isString isFloat isInt isBool isList isAttrs isNull isPath;
|
||||||
inherit (builtins) concatStringsSep filter mapAttrs attrValues;
|
inherit (builtins) concatStringsSep filter mapAttrs attrValues;
|
||||||
|
|
||||||
|
# Source: https://github.com/NixOS/nixpkgs/blob/12f0044f83517e653d0b4fe12a99d162d9407437/lib/trivial.nix#L357
|
||||||
|
warn = msg: builtins.trace "[1;31mwarning: ${msg}[0m";
|
||||||
|
|
||||||
mkLuaRaw = raw: { _type = "raw"; inherit raw; };
|
mkLuaRaw = raw: { _type = "raw"; inherit raw; };
|
||||||
isLuaRaw = expr: getType expr == "raw";
|
isLuaRaw = expr: getType expr == "raw";
|
||||||
|
|
||||||
mkLuaNil = { _type = "nil"; };
|
LuaNil = { _type = "nil"; };
|
||||||
isLuaNil = expr: getType expr == "nil";
|
isLuaNil = expr: getType expr == "nil";
|
||||||
|
|
||||||
|
# DEPRECATED
|
||||||
|
mkLuaNil = warn "`mkLuaNil` is deprecated. Use `LuaNil` instead" LuaNil;
|
||||||
|
|
||||||
mkNamedField = name: expr: {
|
mkNamedField = name: expr: {
|
||||||
_type = "table_field";
|
_type = "table_field";
|
||||||
name = validString name;
|
name = validString name;
|
||||||
|
@ -74,5 +80,7 @@ let
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
inherit toLua;
|
inherit toLua;
|
||||||
inherit mkLuaNil mkLuaRaw mkNamedField;
|
inherit LuaNil mkLuaRaw mkNamedField;
|
||||||
|
# DEPRECATED
|
||||||
|
inherit mkLuaNil;
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
|
|
||||||
let
|
let
|
||||||
nix2lua = import ./lib.nix;
|
nix2lua = import ./lib.nix;
|
||||||
inherit (nix2lua) toLua mkLuaNil mkLuaRaw mkNamedField;
|
inherit (nix2lua) toLua LuaNil mkLuaRaw mkNamedField;
|
||||||
inherit (builtins) tryEval;
|
inherit (builtins) tryEval;
|
||||||
|
|
||||||
failed = { success = false; value = false; };
|
failed = { success = false; value = false; };
|
||||||
|
@ -29,13 +29,17 @@ pkgs.lib.runTests {
|
||||||
expected = null;
|
expected = null;
|
||||||
};
|
};
|
||||||
"test returns nil" = {
|
"test returns nil" = {
|
||||||
expr = toLua mkLuaNil;
|
expr = toLua LuaNil;
|
||||||
expected = "nil";
|
expected = "nil";
|
||||||
};
|
};
|
||||||
"test returns a lua string" = {
|
"test returns a lua string" = {
|
||||||
expr = toLua "hello world";
|
expr = toLua "hello world";
|
||||||
expected = "\"hello world\"";
|
expected = "\"hello world\"";
|
||||||
};
|
};
|
||||||
|
"test returns a path as a lua string" = {
|
||||||
|
expr = toLua /hello/world;
|
||||||
|
expected = "\"/hello/world\"";
|
||||||
|
};
|
||||||
"test returns an integer number" = {
|
"test returns an integer number" = {
|
||||||
expr = toLua 10;
|
expr = toLua 10;
|
||||||
expected = "10";
|
expected = "10";
|
||||||
|
|
Loading…
Reference in a new issue