From e1eb652ef4faab5de04478216124baf2a490cade Mon Sep 17 00:00:00 2001 From: MihailRis Date: Thu, 27 Jun 2024 16:07:40 +0300 Subject: [PATCH] add entity.exists(...) --- src/logic/scripting/lua/libentity.cpp | 5 +++++ src/objects/Entities.hpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/src/logic/scripting/lua/libentity.cpp b/src/logic/scripting/lua/libentity.cpp index fbc19c1c..42cc01fb 100644 --- a/src/logic/scripting/lua/libentity.cpp +++ b/src/logic/scripting/lua/libentity.cpp @@ -22,6 +22,10 @@ static std::optional get_entity(lua::State* L, int idx) { return level->entities->get(id); } +static int l_exists(lua::State* L) { + return lua::pushboolean(L, get_entity(L, 1).has_value()); +} + static int l_spawn(lua::State* L) { auto level = controller->getLevel(); auto defname = lua::tostring(L, 1); @@ -102,6 +106,7 @@ static int l_get_size(lua::State* L) { } const luaL_Reg entitylib [] = { + {"exists", lua::wrap}, {"spawn", lua::wrap}, {"despawn", lua::wrap}, {NULL, NULL} diff --git a/src/objects/Entities.hpp b/src/objects/Entities.hpp index 1e020605..c4845e00 100644 --- a/src/objects/Entities.hpp +++ b/src/objects/Entities.hpp @@ -90,6 +90,10 @@ public: } return std::nullopt; } + + inline size_t size() const { + return entities.size(); + } }; #endif // OBJECTS_ENTITIES_HPP_