Skip to content

Namespace Engine::LuaAPI

Namespace List > Engine > LuaAPI

Namespaces

Type Name
namespace Internal

Public Functions

Type Name
void openStandardLibraries (lua_State * L)
Opens the standard Lua libraries on the state.
void registerAnimation (sol::state_view lua, Registry & registry)
Registers the animation bindings in the Component namespace. MirrorsEngine 'sAnimationPlugin / AnimationComponent.
void registerAudio (sol::state_view lua, Registry & registry)
void registerCamera (sol::state_view lua, Registry & registry)
void registerCollider (sol::state_view lua, Registry & registry)
Registers collider bindings in the Component namespace. MirrorsEngine 'sColliderPlugin /ColliderComponent .
void registerComponentQuery (sol::state_view lua, Registry & registry)
Registers the cross-component query half of the Component namespace:Component.has(entity, tag) andComponent.remove(entity, tag) .
void registerConnections (sol::state_view lua, Registry & registry)
Registers Godot-style connection bindings in the Component namespace.
void registerController (sol::state_view lua, Registry & registry)
Registers the Controller namespace: action-based input backed by theEngine 'sInputManager /Controller (one file perEngine plugin).
void registerEngineAPI (lua_State * L, Registry & registry)
Registers every Engine API module into the Lua state.
void registerEntity (sol::state_view lua, Registry & registry)
Registers the Entity namespace: create/destroy/queueDestroy/find/getName/setName.
void registerInput (sol::state_view lua)
Registers the Input namespace: keyboard polling, mouse position, and theKEY.* constant table. MirrorsEngine 'sInputPlugin /Controller (keyboard + mouse devices).
void registerLog (sol::state_view lua)
Registers the log namespace and the globalprint .log.error is a user error: the editor Console shows it and the terminal worker writes it.print ,log.info , andlog.debug go to the terminal only.
void registerMultiplayer (const sol::state_view & lua, Registry & registry)
void registerOpacity (sol::state_view lua, Registry & registry)
Registers opacity bindings in the Component namespace. MirrorsEngine 'sOpacityPlugin /Opacity component.
void registerParent (sol::state_view lua, Registry & registry)
Registers parenting bindings in the Component namespace. MirrorsEngine 'sHierarchyPlugin /Parent component.
void registerPool (sol::state_view lua, Registry & registry)
void registerPosition (sol::state_view lua, Registry & registry)
Registers the position half of the Transform namespace: getPosition ({x, y, z}) / setPosition (x, y [, z]) / translate / getZIndex / setZIndex. MirrorsEngine 'sPositionPlugin /PositionSystem .
void registerRotation (sol::state_view lua, Registry & registry)
Registers the rotation half of the Transform namespace: getRotation / setRotation / rotate. MirrorsEngine 'sRotationPlugin .
void registerScene (sol::state_view lua, Registry & registry)
Registers the Scene namespace:Scene.load(name) andScene.current() .
void registerScript (const sol::state_view & lua, Registry & registry)
Registers script-attachment bindings in the Component namespace. MirrorsEngine 'sScriptComponent /ScriptSystem .
void registerShape (sol::state_view lua, Registry & registry)
Registers Component.addShape . MirrorsEngine 'sShapePlugin /ShapeComponent .
void registerSprite (sol::state_view lua, Registry & registry)
Registers the sprite bindings in the Component namespace. MirrorsEngine 'sSpritePlugin /SpriteComponent .
void registerText (sol::state_view lua, Registry & registry)
Registers Component.addText . MirrorsEngine 'sTextPlugin /Text component.
void registerTime (sol::state_view lua)
Registers the Time namespace (Time.time ,Time.deltaTime ).

Public Functions Documentation

function openStandardLibraries

Opens the standard Lua libraries on the state.

void Engine::LuaAPI::openStandardLibraries (
    lua_State * L
) 

Parameters:

  • L Raw Lua state.

function registerAnimation

Registers the animation bindings in the Component namespace. MirrorsEngine 'sAnimationPlugin / AnimationComponent.

void Engine::LuaAPI::registerAnimation (
    sol::state_view lua,
    Registry & registry
) 

Getters return nil (or false) when the entity has no Animation component. The clip state is advanced by AnimationSystem; scripts only pick a clip and toggle playback.

  • Component.addAnimation(entity, pathsOrSheet [, frameWidth, frameHeight, totalFrames, frameDuration, loop]) -> bool
  • Component.playAnimation(entity, clipName [, restartIfSame]) -> bool
  • Component.getAnimation(entity) -> clip name or nil
  • Component.getAnimationClips(entity) -> {name1, name2, ...} or nil
  • Component.setAnimationPlaying(entity, playing) -> bool
  • Component.isAnimationPlaying(entity) -> bool
  • Component.getAnimationFrame(entity) -> frame index or nil
  • Component.setAnimationFlip(entity, flipX [, flipY]) -> bool
  • Component.getAnimationFlip(entity) -> {flipX = bool, flipY = bool} or nil

pathsOrSheet is either a table of frame image paths (one clip from multiple files) or a single spritesheet path sliced with frameWidth and frameHeight.

Parameters:

  • lua View of the shared Lua state.
  • registry ECS registry; also owns the AssetManager resource.

function registerAudio

void Engine::LuaAPI::registerAudio (
    sol::state_view lua,
    Registry & registry
) 

function registerCamera

void Engine::LuaAPI::registerCamera (
    sol::state_view lua,
    Registry & registry
) 

function registerCollider

Registers collider bindings in the Component namespace. MirrorsEngine 'sColliderPlugin /ColliderComponent .

void Engine::LuaAPI::registerCollider (
    sol::state_view lua,
    Registry & registry
) 

  • Component.addBoxCollider(entity, w, h [, isTrigger [, isStatic]]) -> bool Reconfigures an existing collider in place: the shape is always replaced, but layer/mask/enabled (and any flag that was not passed) are preserved.
  • Component.getColliderSize(entity) -> {w, h, width, height} table or nil
  • Component.setColliderSize(entity, w, h) -> bool
  • Component.getColliderEnabled(entity) -> bool or nil
  • Component.setColliderEnabled(entity, v) -> bool
  • Component.getColliderTrigger(entity) -> bool or nil
  • Component.setColliderTrigger(entity, v) -> bool
  • Component.getColliderStatic(entity) -> bool or nil
  • Component.setColliderStatic(entity, v) -> bool
  • Component.getColliderLayer(entity) -> int or nil
  • Component.getColliderLayerName(entity) -> string or nil
  • Component.setColliderLayer(entity, layerOrName) -> bool
  • Component.getColliderMask(entity) -> int or nil
  • Component.setColliderMask(entity, mask) -> bool
  • Component.collidersCanCollide(a, b) -> bool (the CollisionSystem pair filter)
  • Component.isColliding(entity) -> bool (polls CollisionSystem contacts)
  • Component.getCollisions(entity) -> array table of other entity ids

Also registers the Layers namespace: Layers.name(i), Layers.index("Enemy"), Layers.bit(i | "Enemy"), Layers.all, Layers.none, Layers.count.

Removal uses the existing generic Component.remove(entity, "Collider").

Parameters:

  • lua View of the shared Lua state (used at registration time only).
  • registry ECS registry used to add the Collider component.

function registerComponentQuery

Registers the cross-component query half of the Component namespace:Component.has(entity, tag) andComponent.remove(entity, tag) .

void Engine::LuaAPI::registerComponentQuery (
    sol::state_view lua,
    Registry & registry
) 

These two functions dispatch across every registered component type, so they deliberately live in their own file referred to by every component module.

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry used to query and remove components.

function registerConnections

Registers Godot-style connection bindings in the Component namespace.

void Engine::LuaAPI::registerConnections (
    sol::state_view lua,
    Registry & registry
) 

  • Component.connect(emitter, signal, target, method) -> bool (idempotent: re-connecting the exact tuple returns true without duplicating, so script reloads that re-run onCreate stay clean; false on dead emitter/target or unknown signal)
  • Component.disconnect(emitter, signal [, target [, method]]) -> bool (true when anything was removed)
  • Component.getConnections(emitter) -> array of {signal, target, method} tables

Connections are plain data on SignalConnections: the target method is re-resolved at dispatch, so they survive save/load and script reloads.

Parameters:

  • lua View of the shared Lua state (used at registration time only).
  • registry ECS registry holding the entities.

function registerController

Registers the Controller namespace: action-based input backed by theEngine 'sInputManager /Controller (one file perEngine plugin).

void Engine::LuaAPI::registerController (
    sol::state_view lua,
    Registry & registry
) 

Exposes: * Controller.isActionActive(action [, playerId]) * Controller.getActiveActions([playerId]) * Controller.addKeybind(action, key [, deviceType [, composeKey [, playerId [, networked]]]]) networked (default false) marks the bind's action as sent to the server in player_input. * Controller.hasController([playerId]) * Controller.KEYBOARD / MOUSE / GAMEPAD / TOUCH device constants

Player IDs default to 1. The InputManager resource and the player controller are created on demand so Lua-first workflows (no C++ recompilation, editor preview with no C++ keybind setup) work. Application::PreUpdate already calls InputManager::Update() every frame, so scripts only query / bind.

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry holding the InputManager resource.

function registerEngineAPI

Registers every Engine API module into the Lua state.

void Engine::LuaAPI::registerEngineAPI (
    lua_State * L,
    Registry & registry
) 

Called once by ScriptSystem on its first Update. After this returns, Lua scripts can call Entity .*, Transform.*, Component.*, Input .*, Time.*, Scene.*, log.* and print.

Parameters:

  • L Raw Lua state.
  • registry ECS registry handed to the component-backed modules.

function registerEntity

Registers the Entity namespace: create/destroy/queueDestroy/find/getName/setName.

void Engine::LuaAPI::registerEntity (
    sol::state_view lua,
    Registry & registry
) 

queueDestroy defers destruction to FlushQueues (end of frame) and is the only safe destroy inside signal/collision callbacks.

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry used for entity creation, lookup, and Name.

function registerInput

Registers the Input namespace: keyboard polling, mouse position, and theKEY.* constant table. MirrorsEngine 'sInputPlugin /Controller (keyboard + mouse devices).

void Engine::LuaAPI::registerInput (
    sol::state_view lua
) 

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).

function registerLog

Registers the log namespace and the globalprint .log.error is a user error: the editor Console shows it and the terminal worker writes it.print ,log.info , andlog.debug go to the terminal only.

void Engine::LuaAPI::registerLog (
    sol::state_view lua
) 

Corresponds to the Engine logging subsystem (Logging/Logger.hpp).

Parameters:

  • lua View of the shared Lua state.

function registerMultiplayer

void Engine::LuaAPI::registerMultiplayer (
    const sol::state_view & lua,
    Registry & registry
) 

function registerOpacity

Registers opacity bindings in the Component namespace. MirrorsEngine 'sOpacityPlugin /Opacity component.

void Engine::LuaAPI::registerOpacity (
    sol::state_view lua,
    Registry & registry
) 

  • Component.setOpacity(entity, alpha [, inherit]) -> bool (creates or updates, alpha clamped to [0, 1])
  • Component.getOpacity(entity) -> alpha number or nil
  • Component.setOpacityInherit(entity, inherit) / get flag for the "inherit to children" checkbox

Removal uses the existing generic Component.remove(entity, " Opacity ").

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry holding the entities.

function registerParent

Registers parenting bindings in the Component namespace. MirrorsEngine 'sHierarchyPlugin /Parent component.

void Engine::LuaAPI::registerParent (
    sol::state_view lua,
    Registry & registry
) 

  • Component.setParent(child, parent [, relative]) -> bool
  • Component.getParent(entity) -> parent id or nil
  • Component.getChildren(entity) -> array table of child ids
  • Component.flipX(entity) -> bool

flipX mirrors a whole rig: the entity's sprite flips and every descendant's footprint is reflected about the entity's centre, so children (front sensors, mounts) swap sides. It is a toggle, meant to be called once per direction change; Component.getSpriteFlip reads the facing back.

Detaching uses the existing generic Component.remove(entity, " Parent "). setParent reuses HierarchyPlugin::AttachChild, so self-parenting and cycles are rejected (returns false). The Parent component type is registered idempotently here so Lua-first games work without HierarchyPlugin init.

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry holding the entities.

function registerPool

void Engine::LuaAPI::registerPool (
    sol::state_view lua,
    Registry & registry
) 

function registerPosition

Registers the position half of the Transform namespace: getPosition ({x, y, z}) / setPosition (x, y [, z]) / translate / getZIndex / setZIndex. MirrorsEngine 'sPositionPlugin /PositionSystem .

void Engine::LuaAPI::registerPosition (
    sol::state_view lua,
    Registry & registry
) 

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry used to read/write the Position component.

function registerRotation

Registers the rotation half of the Transform namespace: getRotation / setRotation / rotate. MirrorsEngine 'sRotationPlugin .

void Engine::LuaAPI::registerRotation (
    sol::state_view lua,
    Registry & registry
) 

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry used to read/write the Rotation component.

function registerScene

Registers the Scene namespace:Scene.load(name) andScene.current() .

void Engine::LuaAPI::registerScene (
    sol::state_view lua,
    Registry & registry
) 

Both go through the registry's SceneManager resource. load takes a code scene name or a scene file path and switches at the end of the frame. In multiplayer only the server's load counts: clients ignore their own calls and follow the server.

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry Registry holding the SceneManager resource.

function registerScript

Registers script-attachment bindings in the Component namespace. MirrorsEngine 'sScriptComponent /ScriptSystem .

void Engine::LuaAPI::registerScript (
    const sol::state_view & lua,
    Registry & registry
) 

  • Component.addScript(entity, scriptPath [, autoReload]) -> bool
  • Component.getScriptPath(entity) -> string or nil

The path is relative to the project folder (same convention as the scriptPath field of a scene), e.g. "scripts/playerGun.lua". The script is loaded by ScriptSystem on the next tick, so onCreate/onUpdate start running after the current frame.

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry holding the entities.

function registerShape

Registers Component.addShape . MirrorsEngine 'sShapePlugin /ShapeComponent .

void Engine::LuaAPI::registerShape (
    sol::state_view lua,
    Registry & registry
) 

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry used to add the Shape component.

function registerSprite

Registers the sprite bindings in the Component namespace. MirrorsEngine 'sSpritePlugin /SpriteComponent .

void Engine::LuaAPI::registerSprite (
    sol::state_view lua,
    Registry & registry
) 

Getters return nil when the entity has no SpriteComponent; setters return false in that case (setSpritePath also returns false when the texture cannot be loaded). Paths are resolved like everywhere else in the engine: project-relative in built games (whose working directory is the project folder), absolute otherwise.

  • Component.getSpriteFlip(entity) -> {flipX = bool, flipY = bool} or nil
  • Component.setSpriteFlip(entity, flipX [, flipY]) -> bool

The flip flags only mirror the drawn sprite. To mirror a whole rig (sprite plus its children), use Component.flipX.

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry; also owns the AssetManager resource.

function registerText

Registers Component.addText . MirrorsEngine 'sTextPlugin /Text component.

void Engine::LuaAPI::registerText (
    sol::state_view lua,
    Registry & registry
) 

Parameters:

  • lua View of the shared Lua state (lambdas capture a copy by value).
  • registry ECS registry used to add the Text component.

function registerTime

Registers the Time namespace (Time.time ,Time.deltaTime ).

void Engine::LuaAPI::registerTime (
    sol::state_view lua
) 

Parameters:

  • lua View of the shared Lua state.


The documentation for this class was generated from the following file /home/runner/work/r-type/r-type/Engine/include/Scripting/LuaAPI.hpp