mirror of
https://github.com/luanti-org/luanti.git
synced 2025-08-01 17:38:41 +00:00
Add warning for initial properties directly inside definition (#9650)
This commit is contained in:
parent
98f097dc2f
commit
c6a0ead72d
7 changed files with 95 additions and 5 deletions
|
@ -181,8 +181,39 @@ std::string ScriptApiEntity::luaentity_GetStaticdata(u16 id)
|
|||
return std::string(s, len);
|
||||
}
|
||||
|
||||
void ScriptApiEntity::logDeprecationForExistingProperties(lua_State *L, int index, const std::string &name)
|
||||
{
|
||||
if (deprecation_warned_init_properties.find(name) != deprecation_warned_init_properties.end())
|
||||
return;
|
||||
|
||||
if (index < 0)
|
||||
index = lua_gettop(L) + 1 + index;
|
||||
|
||||
if (!lua_istable(L, index))
|
||||
return;
|
||||
|
||||
for (const char *key : object_property_keys) {
|
||||
lua_getfield(L, index, key);
|
||||
bool exists = !lua_isnil(L, -1);
|
||||
lua_pop(L, 1);
|
||||
|
||||
if (exists) {
|
||||
std::ostringstream os;
|
||||
|
||||
os << "Reading initial object properties directly from an entity definition is deprecated, "
|
||||
<< "move it to the 'initial_properties' table instead. "
|
||||
<< "(Property '" << key << "' in entity '" << name << "')" << std::endl;
|
||||
|
||||
log_deprecated(L, os.str(), -1);
|
||||
|
||||
deprecation_warned_init_properties.insert(name);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ScriptApiEntity::luaentity_GetProperties(u16 id,
|
||||
ServerActiveObject *self, ObjectProperties *prop)
|
||||
ServerActiveObject *self, ObjectProperties *prop, const std::string &entity_name)
|
||||
{
|
||||
SCRIPTAPI_PRECHECKHEADER
|
||||
|
||||
|
@ -195,6 +226,7 @@ void ScriptApiEntity::luaentity_GetProperties(u16 id,
|
|||
prop->hp_max = 10;
|
||||
|
||||
// Deprecated: read object properties directly
|
||||
logDeprecationForExistingProperties(L, -1, entity_name);
|
||||
read_object_properties(L, -1, self, prop, getServer()->idef());
|
||||
|
||||
// Read initial_properties
|
||||
|
|
|
@ -21,6 +21,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
|
|||
|
||||
#include "cpp_api/s_base.h"
|
||||
#include "irr_v3d.h"
|
||||
#include <unordered_set>
|
||||
|
||||
struct ObjectProperties;
|
||||
struct ToolCapabilities;
|
||||
|
@ -37,7 +38,7 @@ public:
|
|||
void luaentity_Remove(u16 id);
|
||||
std::string luaentity_GetStaticdata(u16 id);
|
||||
void luaentity_GetProperties(u16 id,
|
||||
ServerActiveObject *self, ObjectProperties *prop);
|
||||
ServerActiveObject *self, ObjectProperties *prop, const std::string &entity_name);
|
||||
void luaentity_Step(u16 id, float dtime,
|
||||
const collisionMoveResult *moveresult);
|
||||
bool luaentity_Punch(u16 id,
|
||||
|
@ -51,4 +52,11 @@ public:
|
|||
private:
|
||||
bool luaentity_run_simple_callback(u16 id, ServerActiveObject *sao,
|
||||
const char *field);
|
||||
|
||||
void logDeprecationForExistingProperties(lua_State *L, int index, const std::string &name);
|
||||
|
||||
/** Stores names of entities that already caused a deprecation warning due to
|
||||
* properties being outside of initial_properties. If an entity's name is in here,
|
||||
* it won't cause any more of those deprecation warnings. */
|
||||
std::unordered_set<std::string> deprecation_warned_init_properties;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue