19 inline ecs_value_t get_const_var(
const flecs::world_t *world,
const char *name) {
21 world, 0, name,
"::",
"::",
false);
23 ecs_warn(
"unresolved const variable '%s', returning default", name);
28 if (value.
ptr ==
nullptr) {
29 ecs_warn(
"entity '%s' is not a const variable, returning default",
38 inline T get_const_value(
41 char *requested_type = ecs_get_path(world, type);
42 char *var_type = ecs_get_path(world, value.
type);
43 ecs_warn(
"cannot cast const variable '%s' from type '%s' to '%s', "
44 "returning default", name, var_type, requested_type);
45 ecs_os_free(requested_type);
46 ecs_os_free(var_type);
51 inline char get_const_value<char>(
54 (void)name; (void)type; (void)default_value;
60 inline int8_t get_const_value<int8_t>(
63 (void)name; (void)type; (void)default_value;
69 inline int16_t get_const_value<int16_t>(
72 (void)name; (void)type; (void)default_value;
78 inline int32_t get_const_value<int32_t>(
81 (void)name; (void)type; (void)default_value;
87 inline int64_t get_const_value<int64_t>(
90 (void)name; (void)type; (void)default_value;
96 inline uint8_t get_const_value<uint8_t>(
99 (void)name; (void)type; (void)default_value;
105 inline uint16_t get_const_value<uint16_t>(
108 (void)name; (void)type; (void)default_value;
114 inline uint32_t get_const_value<uint32_t>(
117 (void)name; (void)type; (void)default_value;
123 inline uint64_t get_const_value<uint64_t>(
126 (void)name; (void)type; (void)default_value;
132 inline float get_const_value<float>(
135 (void)name; (void)type; (void)default_value;
141 inline double get_const_value<double>(
144 (void)name; (void)type; (void)default_value;
151inline T world::get_const_var(
153 const T& default_value)
const
155 ecs_value_t value = flecs::_::get_const_var(world_, name);
157 return default_value;
161 if (type == value.
type) {
162 return *(
static_cast<T*
>(value.
ptr));
165 return flecs::_::get_const_value<T>(
166 world_, name, value, type, default_value);
170void world::get_const_var(
173 const T& default_value)
const
175 ecs_value_t value = flecs::_::get_const_var(world_, name);
182 if (type == value.
type) {
183 out = *(
static_cast<T*
>(value.
ptr));
187 out = flecs::_::get_const_value<T>(
188 world_, name, value, type, default_value);
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.
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.