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

View File

@ -22,6 +22,10 @@ static std::optional<Entity> 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<l_exists>},
{"spawn", lua::wrap<l_spawn>},
{"despawn", lua::wrap<l_despawn>},
{NULL, NULL}

View File

@ -90,6 +90,10 @@ public:
}
return std::nullopt;
}
inline size_t size() const {
return entities.size();
}
};
#endif // OBJECTS_ENTITIES_HPP_