20 inline ecs_value_t get_const_var(
const flecs::world_t *world,
const char *name) {
22 world, 0, name,
"::",
"::",
false);
24 ecs_warn(
"unresolved const variable '%s', returning default", name);
29 if (value.
ptr ==
nullptr) {
30 ecs_warn(
"entity '%s' is not a const variable, returning default",
39 inline T get_const_value(
42 char *requested_type = ecs_get_path(world, type);
43 char *var_type = ecs_get_path(world, value.
type);
44 ecs_warn(
"cannot cast const variable '%s' from type '%s' to '%s', "
45 "returning default", name, var_type, requested_type);
46 ecs_os_free(requested_type);
47 ecs_os_free(var_type);
52 inline char get_const_value<char>(
55 (void)name; (void)type; (void)default_value;
61 inline int8_t get_const_value<int8_t>(
64 (void)name; (void)type; (void)default_value;
70 inline int16_t get_const_value<int16_t>(
73 (void)name; (void)type; (void)default_value;
79 inline int32_t get_const_value<int32_t>(
82 (void)name; (void)type; (void)default_value;
88 inline int64_t get_const_value<int64_t>(
91 (void)name; (void)type; (void)default_value;
97 inline uint8_t get_const_value<uint8_t>(
100 (void)name; (void)type; (void)default_value;
106 inline uint16_t get_const_value<uint16_t>(
109 (void)name; (void)type; (void)default_value;
115 inline uint32_t get_const_value<uint32_t>(
118 (void)name; (void)type; (void)default_value;
124 inline uint64_t get_const_value<uint64_t>(
127 (void)name; (void)type; (void)default_value;
133 inline float get_const_value<float>(
136 (void)name; (void)type; (void)default_value;
142 inline double get_const_value<double>(
145 (void)name; (void)type; (void)default_value;
152inline T world::get_const_var(
154 const T& default_value)
const
156 ecs_value_t value = flecs::_::get_const_var(world_, name);
158 return default_value;
162 if (type == value.
type) {
163 return *(
static_cast<T*
>(value.
ptr));
166 return flecs::_::get_const_value<T>(
167 world_, name, value, type, default_value);
171void world::get_const_var(
174 const T& default_value)
const
176 ecs_value_t value = flecs::_::get_const_var(world_, name);
183 if (type == value.
type) {
184 out = *(
static_cast<T*
>(value.
ptr));
188 out = flecs::_::get_const_value<T>(
189 world_, name, value, type, default_value);
197 world.
component<Script>(
"flecs::script::Script");
FLECS_API ecs_entity_t ecs_script_init(ecs_world_t *world, const ecs_script_desc_t *desc)
Load managed script.
FLECS_API ecs_value_t ecs_const_var_get(const ecs_world_t *world, ecs_entity_t var)
Returns value for a const variable.
ecs_id_t ecs_entity_t
An entity identifier.
script_builder script(const char *name=nullptr) const
Build script.
flecs::component< T > component(Args &&... args) const
Find or register component.
ecs_entity_t ecs_lookup_path_w_sep(const ecs_world_t *world, ecs_entity_t parent, const char *path, const char *sep, const char *prefix, bool recursive)
Lookup an entity from a path.
Utility to hold a value of a dynamic type.
void * ptr
Pointer to value.
ecs_entity_t type
Type of value.