Turbo Engine 0.3
A C++ game engine using Allegro 5
turbo::LuaComponent Class Reference

A component whose behaviour is defined by a Lua script, à la Unity. More...

#include <LuaComponent.hpp>

Inheritance diagram for turbo::LuaComponent:
Collaboration diagram for turbo::LuaComponent:

Classes

struct  Script

Public Member Functions

 LuaComponent (GameObject *parent, std::string script_path)
 ~LuaComponent ()
void load () override
 Called when the component is loaded into the scene.
void update (int delta_time) override
 Logic update. Souldn't be used for anything else than logic.
void on_enable () override
 Called when the component is enabled (Not called on the first initialization).
void on_disable () override
 Called when the component is disabled.
void unload () override
 Called when the component is unloaded.
bool valid () const
 Did the script load and return a table without error?
const std::string & script_path () const
 Path of the .lua file backing this component.
const std::string & script_name () const
 Display name (the script file stem).
void reload ()
 Re-read the script file from disk and re-run it.
std::vector< ScriptFieldfields () const
 Public fields (with their current values) for the inspector.
void set_number (const std::string &name, double value)
 Set a public number field on the script instance.
void set_bool (const std::string &name, bool value)
 Set a public boolean field on the script instance.
void set_string (const std::string &name, const std::string &value)
 Set a public string field on the script instance.
Public Member Functions inherited from turbo::Component
 Component (GameObject *parent)
 Construct a new Component. The component will be automatically added to the GameObject given as parameter.
void disable ()
 Disable the component. Do nothing if already disabled.
void enable ()
 Enable the component. Do nothing if already enabled.
bool is_enabled ()
 Check if the component is enabled.
const char * get_name () const
 Display name of the component (used by the editor).

Additional Inherited Members

Public Attributes inherited from turbo::Component
::std::vector< debug::InspectorObserver * > debug_inspector_observers {}
 Debug use only. List of observed values in the inspector.
Protected Attributes inherited from turbo::Component
GameObjectgameObject = nullptr
bool enabled = true
const char * name = "Unknown"

Detailed Description

A component whose behaviour is defined by a Lua script, à la Unity.

The script is a file returning a table with optional lifecycle methods (load, update, on_enable, on_disable, unload). self.gameObject is the owning GameObject. The header keeps sol2/Lua hidden behind a PIMPL so the rest of the engine and the editor can use LuaComponent without pulling in the Lua headers.

Constructor & Destructor Documentation

◆ LuaComponent()

turbo::LuaComponent::LuaComponent ( GameObject * parent,
std::string script_path )

◆ ~LuaComponent()

turbo::LuaComponent::~LuaComponent ( )
default

Member Function Documentation

◆ fields()

std::vector< ScriptField > turbo::LuaComponent::fields ( ) const

Public fields (with their current values) for the inspector.

◆ load()

void turbo::LuaComponent::load ( )
overridevirtual

Called when the component is loaded into the scene.

Reimplemented from turbo::Component.

◆ on_disable()

void turbo::LuaComponent::on_disable ( )
overridevirtual

Called when the component is disabled.

Reimplemented from turbo::Component.

◆ on_enable()

void turbo::LuaComponent::on_enable ( )
overridevirtual

Called when the component is enabled (Not called on the first initialization).

Reimplemented from turbo::Component.

◆ reload()

void turbo::LuaComponent::reload ( )

Re-read the script file from disk and re-run it.

◆ script_name()

const std::string & turbo::LuaComponent::script_name ( ) const
inline

Display name (the script file stem).

◆ script_path()

const std::string & turbo::LuaComponent::script_path ( ) const
inline

Path of the .lua file backing this component.

◆ set_bool()

void turbo::LuaComponent::set_bool ( const std::string & name,
bool value )

Set a public boolean field on the script instance.

◆ set_number()

void turbo::LuaComponent::set_number ( const std::string & name,
double value )

Set a public number field on the script instance.

◆ set_string()

void turbo::LuaComponent::set_string ( const std::string & name,
const std::string & value )

Set a public string field on the script instance.

◆ unload()

void turbo::LuaComponent::unload ( )
overridevirtual

Called when the component is unloaded.

Reimplemented from turbo::Component.

◆ update()

void turbo::LuaComponent::update ( int delta_time)
overridevirtual

Logic update. Souldn't be used for anything else than logic.

Parameters
delta_timemilliseconds since the last call

Reimplemented from turbo::Component.

◆ valid()

bool turbo::LuaComponent::valid ( ) const
inline

Did the script load and return a table without error?


The documentation for this class was generated from the following files: