From e980b4d4507114c6ba9539a19453c071e5e4f5a2 Mon Sep 17 00:00:00 2001 From: Dmitriy Pleshevskiy Date: Wed, 28 Feb 2024 12:50:08 +0300 Subject: [PATCH] chore: rename LuaNil --- README.md | 2 +- lib.nix | 12 ++++++++++-- lib.test.nix | 8 ++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index c7930f7..ec596cf 100644 --- a/README.md +++ b/README.md @@ -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`. diff --git a/lib.nix b/lib.nix index 09589d0..ac32024 100644 --- a/lib.nix +++ b/lib.nix @@ -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; } diff --git a/lib.test.nix b/lib.test.nix index c4f9512..bc50a44 100644 --- a/lib.test.nix +++ b/lib.test.nix @@ -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";