add entity.exists(...)

This commit is contained in:
MihailRis
2024-06-27 16:07:40 +03:00
parent 4df0f4e1e4
commit e1eb652ef4
2 changed files with 9 additions and 0 deletions
+5
View File
@@ -22,6 +22,10 @@ static std::optional<Entity> get_entity(lua::State* L, int idx) {
return level->entities->get(id); 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) { static int l_spawn(lua::State* L) {
auto level = controller->getLevel(); auto level = controller->getLevel();
auto defname = lua::tostring(L, 1); auto defname = lua::tostring(L, 1);
@@ -102,6 +106,7 @@ static int l_get_size(lua::State* L) {
} }
const luaL_Reg entitylib [] = { const luaL_Reg entitylib [] = {
{"exists", lua::wrap<l_exists>},
{"spawn", lua::wrap<l_spawn>}, {"spawn", lua::wrap<l_spawn>},
{"despawn", lua::wrap<l_despawn>}, {"despawn", lua::wrap<l_despawn>},
{NULL, NULL} {NULL, NULL}
+4
View File
@@ -90,6 +90,10 @@ public:
} }
return std::nullopt; return std::nullopt;
} }
inline size_t size() const {
return entities.size();
}
}; };
#endif // OBJECTS_ENTITIES_HPP_ #endif // OBJECTS_ENTITIES_HPP_