Lua

Events

Functions

Description

trigger an event with the c++ dispatcher

Entity Registry

Functions

Description

create an entity.

destroy an entity

get the numbers of entities

checks whether the requested component is associated with the given entity

get the component linked to the given entity

remove the component linked to the given entity

add the component to the given entity

Events API Documentation

shiva.dispatcher:trigger_[event_name]_event

This function trigger an event using the EnTT dispatcher.

All those functions are automatically generated based on shiva::event.

-- Global signature
shiva.dispatcher:trigger_[event_name]_event(evt_arg);

-- Example of generated one
shiva.dispatcher:trigger_quit_game_event(evt_arg);

Parameters

Name

Description

evt_arg

type -> constructor of the current_event

Example

function on_key_pressed(evt)
    if (evt.keycode == Keyboard.Escape) then
        -- quit_game.hpp take a integer as argument for his construction
        shiva.dispatcher:trigger_quit_game_event(1)
    end
end

Entity Registry API Documentation

shiva.entity_registry:create

This function create an entity through the EnTT registry and return an unique identifier.

shiva.entity_registry:create();

Return value

Possible name

Description

entity_id

integer

  • the entity identifier

Example

function foo()
    local entity_id = shiva.entity_registry:create()
end

shiva.entity_registry:destroy

This function destroy an entity through the EnTT registry.

shiva.entity_registry:destroy(entity_id);

Parameters

Name

Description

entity_id

integer

  • the identifier of the entity to be destroyed.

Example

function foo()
    local id = shiva.entity_registry:create()
    shiva.entity_registry:destroy(id)
end

shiva.entity_registry:nb_entities

This function retrieve the number of entities through the EnTT registry

shiva.entity_registry:nb_entities()

Return value

Possible name

Description

nb_entities

integer

  • the number of entities

Example

function foo()
    local id = shiva.entity_registry:create()
    assert(shiva.entity_registry:nb_entities() == 1)
    shiva.entity_registry:destroy(id)
    assert(shiva.entity_registry:nb_entities() == 0)
end

shiva.entity_registry:has_[component_name]_component

This function checks whether the requested component is associated with the given entity through the EnTT registry

All those functions are automatically generated based on the common components.

-- Global signature
shiva.entity_registry:has_[component_name]_component(entity_id);

-- Example of generated one
shiva.entity_registry:has_layer_1_component(entity_id);

Parameters

Name

Description

entity_id

integer

  • the identifier of the entity to be verified

Return value

Possible name

Description

result

boolean

  • true if the entity has the component

  • false otherwise

Example

function foo()
    local entity_id = shiva.entity_registry:create()
    local component = shiva.entity_registry:add_layer_1_component(entity_id)
    local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
    shiva.entity_registry:remove_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end

shiva.entity_registry:get_[component_name]_component

This function takes an entity as a parameter and retrieves the component associated with it through the EnTT registry.

All those functions are automatically generated based on the common components.

-- Global signature
shiva.entity_registry:get_[component_name]_component(entity_id);

-- Example of generated one
shiva.entity_registry:get_layer_1_component(entity_id);

Parameters

Name

Description

entity_id

integer

  • the identifier of the entity to be get

Return value

Possible Name

Description

same_component

Component &

  • a reference on the requested component

Example

function foo()
    local entity_id = shiva.entity_registry:create()
    local component = shiva.entity_registry:add_layer_1_component(entity_id)
    local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
    shiva.entity_registry:remove_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end

shiva.entity_registry:remove_[component_name]_component

This function takes an entity as a parameter and remove the component associated with it through the EnTT registry.

All those functions are automatically generated based on the common components.

-- Global signature
shiva.entity_registry:remove_[component_name]_component(entity_id);

-- Example of generated one
shiva.entity_registry:remove_layer_1_component(entity_id);

Parameters

Name

Description

entity_id

integer

  • the identifier of the entity to be remove.

Example

function foo()
    local entity_id = shiva.entity_registry:create()
    local component = shiva.entity_registry:add_layer_1_component(entity_id)
    local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
    shiva.entity_registry:remove_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end

shiva.entity_registry:add_[component_name]_component

This function takes an entity as a parameter and add the component through the EnTT registry, and return a reference to the component.

All those functions are automatically generated based on the common components.

-- Global signature
shiva.entity_registry:add_[component_name]_component(entity_id);

-- Example of generated one
shiva.entity_registry:add_layer_1_component(entity_id);

Parameters

Name

Description

entity_id

integer

  • the identifier of the entity which will add the component

Return value

Possible name

Description

component

Component &

  • a reference on the created component

Example

function foo()
    local entity_id = shiva.entity_registry:create()
    local component = shiva.entity_registry:add_layer_1_component(entity_id)
    local same_component = shiva.entity_registry:get_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == true, "should be true")
    shiva.entity_registry:remove_layer_1_component(entity_id)
    assert(shiva.entity_registry:has_layer_1_component(entity_id) == false, "should be false")
end

Last updated