From 321b217feb9243d3689edcca26ededf3f8d87fc6 Mon Sep 17 00:00:00 2001 From: 1F616EMO~nya Date: Mon, 1 Jul 2024 23:26:15 +0800 Subject: [PATCH] Log node/ore name when detecting deprecated fields (#14794) --- src/script/common/c_content.cpp | 17 ++++++++++------- src/script/common/c_converter.h | 3 ++- src/script/lua_api/l_mapgen.cpp | 6 +++--- 3 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 988094b9f..6f7d86447 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -760,7 +760,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) f.setDefaultAlphaMode(); - warn_if_field_exists(L, index, "alpha", + warn_if_field_exists(L, index, "alpha", "node " + f.name, "Obsolete, only limited compatibility provided; " "replaced by \"use_texture_alpha\""); if (getintfield_default(L, index, "alpha", 255) != 255) @@ -768,7 +768,7 @@ void read_content_features(lua_State *L, ContentFeatures &f, int index) lua_getfield(L, index, "use_texture_alpha"); if (lua_isboolean(L, -1)) { - warn_if_field_exists(L, index, "use_texture_alpha", + warn_if_field_exists(L, index, "use_texture_alpha", "node " + f.name, "Boolean values are deprecated; use the new choices"); if (lua_toboolean(L, -1)) f.alpha = (f.drawtype == NDT_NORMAL) ? ALPHAMODE_CLIP : ALPHAMODE_BLEND; @@ -1315,13 +1315,16 @@ void pushnode(lua_State *L, const MapNode &n) } /******************************************************************************/ -void warn_if_field_exists(lua_State *L, int table, - const char *name, const std::string &message) +void warn_if_field_exists(lua_State *L, int table, const char *fieldname, + std::string_view name, std::string_view message) { - lua_getfield(L, table, name); + lua_getfield(L, table, fieldname); if (!lua_isnil(L, -1)) { - warningstream << "Field \"" << name << "\": " - << message << std::endl; + warningstream << "Field \"" << fieldname << "\""; + if (!name.empty()) { + warningstream << " on " << name; + } + warningstream << ": " << message << std::endl; infostream << script_get_backtrace(L) << std::endl; } lua_pop(L, 1); diff --git a/src/script/common/c_converter.h b/src/script/common/c_converter.h index 05d43953e..04f1ba0f9 100644 --- a/src/script/common/c_converter.h +++ b/src/script/common/c_converter.h @@ -120,7 +120,8 @@ void push_aabb3f_vector (lua_State *L, const std::vector void warn_if_field_exists(lua_State *L, int table, const char *fieldname, - const std::string &message); + std::string_view name, + std::string_view message); size_t write_array_slice_float(lua_State *L, int table_index, float *data, v3u16 data_size, v3u16 slice_offset, v3u16 slice_size); diff --git a/src/script/lua_api/l_mapgen.cpp b/src/script/lua_api/l_mapgen.cpp index 2b61f0e77..8e1ef97d6 100644 --- a/src/script/lua_api/l_mapgen.cpp +++ b/src/script/lua_api/l_mapgen.cpp @@ -1354,7 +1354,7 @@ int ModApiMapgen::l_register_ore(lua_State *L) ore->flags = 0; //// Get noise_threshold - warn_if_field_exists(L, index, "noise_threshhold", + warn_if_field_exists(L, index, "noise_threshhold", "ore " + ore->name, "Deprecated: new name is \"noise_threshold\"."); float nthresh; @@ -1364,9 +1364,9 @@ int ModApiMapgen::l_register_ore(lua_State *L) ore->nthresh = nthresh; //// Get y_min/y_max - warn_if_field_exists(L, index, "height_min", + warn_if_field_exists(L, index, "height_min", "ore " + ore->name, "Deprecated: new name is \"y_min\"."); - warn_if_field_exists(L, index, "height_max", + warn_if_field_exists(L, index, "height_max", "ore " + ore->name, "Deprecated: new name is \"y_max\"."); int ymin, ymax;