Flecs v4.1
A fast entity component system (ECS) for C & C++
Loading...
Searching...
No Matches
ecs_function_desc_t Struct Reference

Used with ecs_function_init and ecs_method_init. More...

#include <script.h>

Public Attributes

const char * name
 Function name.
 
ecs_entity_t parent
 Parent of function.
 
ecs_script_parameter_t params [(16)]
 Function parameters.
 
ecs_entity_t return_type
 Function return type.
 
ecs_function_callback_t callback
 Function implementation.
 
ecs_vector_function_callback_t vector_callbacks [(18)]
 Vector function implementations.
 
void * ctx
 Context passed to function implementation.
 

Detailed Description

Used with ecs_function_init and ecs_method_init.

Definition at line 730 of file script.h.

Member Data Documentation

◆ callback

ecs_function_callback_t ecs_function_desc_t::callback

Function implementation.

Definition at line 745 of file script.h.

◆ ctx

void* ecs_function_desc_t::ctx

Context passed to function implementation.

Definition at line 797 of file script.h.

◆ name

const char* ecs_function_desc_t::name

Function name.

Definition at line 732 of file script.h.

◆ params

ecs_script_parameter_t ecs_function_desc_t::params[(16)]

Function parameters.

Definition at line 739 of file script.h.

◆ parent

ecs_entity_t ecs_function_desc_t::parent

Parent of function.

For methods the parent is the type for which the method will be registered.

Definition at line 736 of file script.h.

◆ return_type

ecs_entity_t ecs_function_desc_t::return_type

Function return type.

Definition at line 742 of file script.h.

◆ vector_callbacks

ecs_vector_function_callback_t ecs_function_desc_t::vector_callbacks[(18)]

Vector function implementations.

Set these callbacks if a function has one or more arguments of type flecs.script vector, and optionally a return type of flecs.script.vector.

The flecs.script.vector type allows a function to be called with types that meet the following constraints:

  • The same type is provided for all arguments of type flecs.script.vector
  • The provided type has one or members of the same type
  • The member type must be a primitive type
  • The vector_callbacks array has an implementation for the primitive type.

This allows for statements like:

const a = Rgb: {100, 150, 250}
const b = Rgb: {10, 10, 10}
const r = lerp(a, b, 0.1)

which would otherwise have to be written out as:

const r = Rgb: {
lerp(a.r, b.r, 0.1),
lerp(a.g, b.g, 0.1),
lerp(a.b, b.b, 0.1)
}

To register vector functions, do:

ecs_function(world, {
.name = "lerp",
.return_type = EcsScriptVectorType,
.params = {
{ .name = "a", .type = EcsScriptVectorType },
{ .name = "b", .type = EcsScriptVectorType },
{ .name = "t", .type = ecs_id(ecs_f64_t) }
},
.vector_callbacks = {
[EcsF32] = flecs_lerp32,
[EcsF64] = flecs_lerp64
}
});
FLECS_API const ecs_entity_t ecs_id(EcsDocDescription)
Component id for EcsDocDescription.
double ecs_f64_t
Builtin f64 type.
Definition meta.h:109

Definition at line 794 of file script.h.


The documentation for this struct was generated from the following file: