1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-06-27 16:36:03 +00:00

Change nil-component error to deprecation warning

This commit is contained in:
sfan5 2025-05-26 21:42:21 +02:00
parent 71d76f6c7b
commit a741123a30
3 changed files with 12 additions and 9 deletions

View file

@ -30,10 +30,13 @@ static v3d check_v3d(lua_State *L, int index);
} \ } \
} while(0) } 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 { \ #define CHECK_NOT_NIL(index, name) do { \
if (lua_isnoneornil(L, (index))) { \ if (lua_isnoneornil(L, (index))) { \
throw LuaError(std::string("Invalid ") + (name) + \ auto msg = std::string("Invalid ") + (name) + \
" (value is nil)."); \ " (value is nil)."; \
log_deprecated(L, msg, 1, true); \
} \ } \
} while(0) } while(0)

View file

@ -272,11 +272,11 @@ int ModApiEnv::l_get_node_raw(lua_State *L)
// mirrors the implementation of read_v3s16 (with the exact same rounding) // mirrors the implementation of read_v3s16 (with the exact same rounding)
{ {
if (lua_isnoneornil(L, 1)) 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)) 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)) 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 x = lua_tonumber(L, 1);
double y = lua_tonumber(L, 2); double y = lua_tonumber(L, 2);
double z = lua_tonumber(L, 3); double z = lua_tonumber(L, 3);

View file

@ -144,10 +144,6 @@ void TestScriptApi::testVectorReadErr(MyScriptApi *script)
// both methods should reject these // both methods should reject these
const char *errs1[] = { const char *errs1[] = {
"return {y=1, z=3}",
"return {x=1, z=3}",
"return {x=1, y=3}",
"return {}",
"return 'bamboo'", "return 'bamboo'",
"return function() end", "return function() end",
"return nil", "return nil",
@ -167,6 +163,10 @@ void TestScriptApi::testVectorReadMix(MyScriptApi *script)
// read_v3s16 should allow these, but check_v3s16 should not // read_v3s16 should allow these, but check_v3s16 should not
const std::pair<const char*, v3s16> pairs2[] = { const std::pair<const char*, v3s16> 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='3', y='2.9', z=3}", {3, 3, 3}},
{"return {x=false, y=0, z=0}", {0, 0, 0}}, {"return {x=false, y=0, z=0}", {0, 0, 0}},
{"return {x='?', y=0, z=0}", {0, 0, 0}}, {"return {x='?', y=0, z=0}", {0, 0, 0}},