aboutsummaryrefslogtreecommitdiff
path: root/src/script
diff options
context:
space:
mode:
authorhecks <42101236+hecktest@users.noreply.github.com>2021-01-02 15:14:29 +0100
committerGitHub <noreply@github.com>2021-01-02 15:14:29 +0100
commitdd5a732fa90550066bb96305b64b6648903cc822 (patch)
tree1d39d1362e7619ff459eb6da5f1c9aab7629d1b6 /src/script
parentad58fb22064c7db223cb825596c12f93f2a75a26 (diff)
downloadminetest-dd5a732fa90550066bb96305b64b6648903cc822.tar.gz
minetest-dd5a732fa90550066bb96305b64b6648903cc822.tar.bz2
minetest-dd5a732fa90550066bb96305b64b6648903cc822.zip
Add on_deactivate callback for luaentities (#10723)
Diffstat (limited to 'src/script')
-rw-r--r--src/script/cpp_api/s_entity.cpp26
-rw-r--r--src/script/cpp_api/s_entity.h1
-rw-r--r--src/script/lua_api/l_object.cpp2
3 files changed, 28 insertions, 1 deletions
diff --git a/src/script/cpp_api/s_entity.cpp b/src/script/cpp_api/s_entity.cpp
index ea9320051..746f7013e 100644
--- a/src/script/cpp_api/s_entity.cpp
+++ b/src/script/cpp_api/s_entity.cpp
@@ -103,6 +103,32 @@ void ScriptApiEntity::luaentity_Activate(u16 id,
lua_pop(L, 2); // Pop object and error handler
}
+void ScriptApiEntity::luaentity_Deactivate(u16 id)
+{
+ SCRIPTAPI_PRECHECKHEADER
+
+ verbosestream << "scriptapi_luaentity_deactivate: id=" << id << std::endl;
+
+ int error_handler = PUSH_ERROR_HANDLER(L);
+
+ // Get the entity
+ luaentity_get(L, id);
+ int object = lua_gettop(L);
+
+ // Get on_deactivate
+ lua_getfield(L, -1, "on_deactivate");
+ if (!lua_isnil(L, -1)) {
+ luaL_checktype(L, -1, LUA_TFUNCTION);
+ lua_pushvalue(L, object);
+
+ setOriginFromTable(object);
+ PCALL_RES(lua_pcall(L, 1, 0, error_handler));
+ } else {
+ lua_pop(L, 1);
+ }
+ lua_pop(L, 2); // Pop object and error handler
+}
+
void ScriptApiEntity::luaentity_Remove(u16 id)
{
SCRIPTAPI_PRECHECKHEADER
diff --git a/src/script/cpp_api/s_entity.h b/src/script/cpp_api/s_entity.h
index b5f7a6586..b52f6e447 100644
--- a/src/script/cpp_api/s_entity.h
+++ b/src/script/cpp_api/s_entity.h
@@ -33,6 +33,7 @@ public:
bool luaentity_Add(u16 id, const char *name);
void luaentity_Activate(u16 id,
const std::string &staticdata, u32 dtime_s);
+ void luaentity_Deactivate(u16 id);
void luaentity_Remove(u16 id);
std::string luaentity_GetStaticdata(u16 id);
void luaentity_GetProperties(u16 id,
diff --git a/src/script/lua_api/l_object.cpp b/src/script/lua_api/l_object.cpp
index 4d7a1bc41..f52e4892e 100644
--- a/src/script/lua_api/l_object.cpp
+++ b/src/script/lua_api/l_object.cpp
@@ -110,7 +110,7 @@ int ObjectRef::l_remove(lua_State *L)
sao->clearParentAttachment();
verbosestream << "ObjectRef::l_remove(): id=" << sao->getId() << std::endl;
- sao->m_pending_removal = true;
+ sao->markForRemoval();
return 0;
}