chore: rename LuaNil

This commit is contained in:
Dmitriy Pleshevskiy 2024-02-28 12:50:08 +03:00
parent 222024ed3a
commit e980b4d450
Signed by: pleshevskiy
GPG key ID: 17041163DA10A9A2
3 changed files with 17 additions and 5 deletions

View file

@ -54,7 +54,7 @@ Add nix2lua as input to your flake.nix
> toLua mkLuaNil
> ```
`mkLuaRaw expr`
`LuaRaw expr`
> Creates a type that instructs `toLua` not to change the passed expression
> `expr`.

12
lib.nix
View file

@ -18,12 +18,18 @@ let
inherit (builtins) isString isFloat isInt isBool isList isAttrs isNull isPath;
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; };
isLuaRaw = expr: getType expr == "raw";
mkLuaNil = { _type = "nil"; };
LuaNil = { _type = "nil"; };
isLuaNil = expr: getType expr == "nil";
# DEPRECATED
mkLuaNil = warn "`mkLuaNil` is deprecated. Use `LuaNil` instead" LuaNil;
mkNamedField = name: expr: {
_type = "table_field";
name = validString name;
@ -74,5 +80,7 @@ let
in
{
inherit toLua;
inherit mkLuaNil mkLuaRaw mkNamedField;
inherit LuaNil mkLuaRaw mkNamedField;
# DEPRECATED
inherit mkLuaNil;
}

View file

@ -18,7 +18,7 @@
let
nix2lua = import ./lib.nix;
inherit (nix2lua) toLua mkLuaNil mkLuaRaw mkNamedField;
inherit (nix2lua) toLua LuaNil mkLuaRaw mkNamedField;
inherit (builtins) tryEval;
failed = { success = false; value = false; };
@ -29,13 +29,17 @@ pkgs.lib.runTests {
expected = null;
};
"test returns nil" = {
expr = toLua mkLuaNil;
expr = toLua LuaNil;
expected = "nil";
};
"test returns a lua string" = {
expr = toLua "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" = {
expr = toLua 10;
expected = "10";