diff --git a/iolite_c_api/iolite_api.h b/iolite_c_api/iolite_api.h index 61d9485..8dd2f1e 100644 --- a/iolite_c_api/iolite_api.h +++ b/iolite_c_api/iolite_api.h @@ -2745,6 +2745,11 @@ struct io_entity_i // NOLINT // See "Documentation" for usage details. void (*find_entities_with_name)(const char* name, io_ref_t* entities, io_size_t* entities_length); + // Finds all entities which have a component with the given component type + // name attached. + void (*find_entities_with_component)(const char* component_type_name, + io_ref_t* entities, + io_size_t* entities_length); // Copies and initializes the component of the given type from the source // entity to the given target entity. diff --git a/iolite_plugins/lua_plugin/init_state.cpp b/iolite_plugins/lua_plugin/init_state.cpp index c43bd10..58b1835 100644 --- a/iolite_plugins/lua_plugin/init_state.cpp +++ b/iolite_plugins/lua_plugin/init_state.cpp @@ -1946,9 +1946,9 @@ void script_init_state(sol::state& s) s["Entity"]["find_first_entity_with_name"] = io_entity->find_first_entity_with_name; // @function find_entities_with_name - // @summary Finds all entities with the given name and returns as table containg refs as result. + // @summary Finds all entities with the given name. // @param name string The name of the entities to search for. - // @return table value Table containing the entities with the given name. + // @return table value Table containing the matching entities. s["Entity"]["find_entities_with_name"] = [](const char* name) { uint32_t num_entities; io_entity->find_entities_with_name(name, nullptr, &num_entities); @@ -1957,6 +1957,18 @@ void script_init_state(sol::state& s) return entities; }; + // @function find_entities_with_component + // @summary Finds all entities with a component of the given component type name attached to them. + // @param name string The component type name. + // @return table value Table containing the matching entities. + s["Entity"]["find_entities_with_component"] = [](const char* name) { + uint32_t num_entities; + io_entity->find_entities_with_component(name, nullptr, &num_entities); + std::vector entities(num_entities); + io_entity->find_entities_with_component(name, entities.data(), &num_entities); + + return entities; + }; };