From 5c2599315cb6295196a5dc8f96debc930f28b8ad Mon Sep 17 00:00:00 2001 From: sfan5 Date: Mon, 26 May 2025 21:42:21 +0200 Subject: [PATCH] Change nil-component error to deprecation warning --- src/script/common/c_converter.cpp | 7 +++++-- src/script/lua_api/l_env.cpp | 6 +++--- src/unittest/test_scriptapi.cpp | 8 ++++---- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/script/common/c_converter.cpp b/src/script/common/c_converter.cpp index a8c9ace3a..2b711bfda 100644 --- a/src/script/common/c_converter.cpp +++ b/src/script/common/c_converter.cpp @@ -30,10 +30,13 @@ static v3d check_v3d(lua_State *L, int index); } \ } while(0) +// TODO: this should be turned into an error in 2026. +// Just revert the commit that added this line. #define CHECK_NOT_NIL(index, name) do { \ if (lua_isnoneornil(L, (index))) { \ - throw LuaError(std::string("Invalid ") + (name) + \ - " (value is nil)."); \ + auto msg = std::string("Invalid ") + (name) + \ + " (value is nil)."; \ + log_deprecated(L, msg, 1, true); \ } \ } while(0) diff --git a/src/script/lua_api/l_env.cpp b/src/script/lua_api/l_env.cpp index 423479040..e21a954ac 100644 --- a/src/script/lua_api/l_env.cpp +++ b/src/script/lua_api/l_env.cpp @@ -272,11 +272,11 @@ int ModApiEnv::l_get_node_raw(lua_State *L) // mirrors the implementation of read_v3s16 (with the exact same rounding) { if (lua_isnoneornil(L, 1)) - throw LuaError("X position is nil"); + log_deprecated(L, "X position is nil", 1, true); if (lua_isnoneornil(L, 2)) - throw LuaError("Y position is nil"); + log_deprecated(L, "Y position is nil", 1, true); if (lua_isnoneornil(L, 3)) - throw LuaError("Z position is nil"); + log_deprecated(L, "Z position is nil", 1, true); double x = lua_tonumber(L, 1); double y = lua_tonumber(L, 2); double z = lua_tonumber(L, 3); diff --git a/src/unittest/test_scriptapi.cpp b/src/unittest/test_scriptapi.cpp index 0e407daf5..03c3713b2 100644 --- a/src/unittest/test_scriptapi.cpp +++ b/src/unittest/test_scriptapi.cpp @@ -144,10 +144,6 @@ void TestScriptApi::testVectorReadErr(MyScriptApi *script) // both methods should reject these const char *errs1[] = { - "return {y=1, z=3}", - "return {x=1, z=3}", - "return {x=1, y=3}", - "return {}", "return 'bamboo'", "return function() end", "return nil", @@ -167,6 +163,10 @@ void TestScriptApi::testVectorReadMix(MyScriptApi *script) // read_v3s16 should allow these, but check_v3s16 should not const std::pair pairs2[] = { + {"return {}", {0, 0, 0}}, + {"return {y=1, z=3}", {0, 1, 3}}, + {"return {x=1, z=3}", {1, 0, 3}}, + {"return {x=1, y=3}", {1, 3, 0}}, {"return {x='3', y='2.9', z=3}", {3, 3, 3}}, {"return {x=false, y=0, z=0}", {0, 0, 0}}, {"return {x='?', y=0, z=0}", {0, 0, 0}},