argos::CLuaUtility Class Reference

#include <lua_utility.h>

Static Public Member Functions

static bool LoadScript (lua_State *pt_state, const std::string &str_filename)
 Loads the given Lua script. More...
 
static bool CallLuaFunction (lua_State *pt_state, const std::string &str_function)
 Calls a parameter-less function in the Lua script. More...
 
static void PrintGlobals (CARGoSLog &c_log, lua_State *pt_state)
 Prints the global Lua symbols on the specified log. More...
 
static void PrintStack (CARGoSLog &c_log, lua_State *pt_state)
 Prints the Lua stack on the specified log. More...
 
static void RegisterLoggerWrapper (lua_State *pt_state)
 Registers LOG and LOGERR in the Lua state. More...
 
static void RegisterRNG (lua_State *pt_state, CRandom::CRNG *pc_rng)
 Registers the given random number generator in the Lua state. More...
 
static void OpenRobotStateTable (lua_State *pt_state, const std::string &str_key)
 Opens a table in the robot state, creating it if it does not exist. More...
 
static void CloseRobotStateTable (lua_State *pt_state)
 Closes a table in the robot state. More...
 
static void StartTable (lua_State *pt_state, const std::string &str_key)
 Adds a table with the given string key to the table located at the top of the stack. More...
 
static void StartTable (lua_State *pt_state, int n_key)
 Adds a table with the given numeric key to the table located at the top of the stack. More...
 
static void EndTable (lua_State *pt_state)
 Adds a table to the Lua stack. More...
 
static void SetMetatable (lua_State *pt_state, const std::string &str_key)
 Sets the metatable with the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, void *pt_data)
 Adds a pointer to a chunk of data with the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, lua_CFunction pt_data)
 Adds a pointer to a C function with the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, const std::string &str_data)
 Adds a string with the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, int n_key, const std::string &str_data)
 Adds a string with the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, Real f_data)
 Adds a Real with the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, int n_key, Real f_data)
 Adds a Real with the given numeric key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, const CRadians &c_data)
 Adds a CRadians with the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, int n_key, const CRadians &c_data)
 Adds a CRadians with the given numeric key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, const CVector2 &c_data)
 Adds a CVector2 the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, int n_key, const CVector2 &c_data)
 Adds a CVector2 the given numeric key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, const CVector3 &c_data)
 Adds a CVector3 the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, int n_key, const CVector3 &c_data)
 Adds a CVector3 the given numeric key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, const CQuaternion &c_data)
 Adds a CQuaternion the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, int n_key, const CQuaternion &c_data)
 Adds a CQuaternion the given numeric key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, const std::string &str_key, const CColor &c_data)
 Adds a CColor the given string key to the table located at the top of the stack. More...
 
static void AddToTable (lua_State *pt_state, int n_key, const CColor &c_data)
 Adds a CColor the given numeric key to the table located at the top of the stack. More...
 
template<class T >
static T * GetDeviceInstance (lua_State *pt_state, const std::string &str_key)
 Returns a pointer to the instance to the wanted device. More...
 

Detailed Description

Definition at line 31 of file lua_utility.h.

Member Function Documentation

◆ AddToTable() [1/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
const CColor c_data 
)
static

Adds a CColor the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 538 of file lua_utility.cpp.

◆ AddToTable() [2/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
const CQuaternion c_data 
)
static

Adds a CQuaternion the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 516 of file lua_utility.cpp.

◆ AddToTable() [3/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
const CRadians c_data 
)
static

Adds a CRadians with the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
c_dataThe data to add to the table.

Definition at line 449 of file lua_utility.cpp.

◆ AddToTable() [4/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
const CVector2 c_data 
)
static

Adds a CVector2 the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 471 of file lua_utility.cpp.

◆ AddToTable() [5/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
const CVector3 c_data 
)
static

Adds a CVector3 the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 493 of file lua_utility.cpp.

◆ AddToTable() [6/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
const std::string &  str_data 
)
static

Adds a string with the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
str_dataThe data to add to the table.

Definition at line 405 of file lua_utility.cpp.

◆ AddToTable() [7/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
lua_CFunction  pt_data 
)
static

Adds a pointer to a C function with the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
pt_dataThe data to add to the table.

Definition at line 394 of file lua_utility.cpp.

◆ AddToTable() [8/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
Real  f_data 
)
static

Adds a Real with the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
f_dataThe data to add to the table.

Definition at line 427 of file lua_utility.cpp.

◆ AddToTable() [9/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
const std::string &  str_key,
void *  pt_data 
)
static

Adds a pointer to a chunk of data with the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
pt_dataThe data to add to the table.

Definition at line 383 of file lua_utility.cpp.

◆ AddToTable() [10/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
int  n_key,
const CColor c_data 
)
static

Adds a CColor the given numeric key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 551 of file lua_utility.cpp.

◆ AddToTable() [11/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
int  n_key,
const CQuaternion c_data 
)
static

Adds a CQuaternion the given numeric key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 527 of file lua_utility.cpp.

◆ AddToTable() [12/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
int  n_key,
const CRadians c_data 
)
static

Adds a CRadians with the given numeric key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
c_dataThe data to add to the table.

Definition at line 460 of file lua_utility.cpp.

◆ AddToTable() [13/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
int  n_key,
const CVector2 c_data 
)
static

Adds a CVector2 the given numeric key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 482 of file lua_utility.cpp.

◆ AddToTable() [14/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
int  n_key,
const CVector3 c_data 
)
static

Adds a CVector3 the given numeric key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
c_dataThe data to add to the table.
See also
StartTable()
EndTable()

Definition at line 504 of file lua_utility.cpp.

◆ AddToTable() [15/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
int  n_key,
const std::string &  str_data 
)
static

Adds a string with the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
str_dataThe data to add to the table.

Definition at line 416 of file lua_utility.cpp.

◆ AddToTable() [16/16]

void argos::CLuaUtility::AddToTable ( lua_State *  pt_state,
int  n_key,
Real  f_data 
)
static

Adds a Real with the given numeric key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
f_dataThe data to add to the table.

Definition at line 438 of file lua_utility.cpp.

◆ CallLuaFunction()

bool argos::CLuaUtility::CallLuaFunction ( lua_State *  pt_state,
const std::string &  str_function 
)
static

Calls a parameter-less function in the Lua script.

Parameters
pt_stateThe Lua state.
str_functionThe function name.
Returns
false in case of errors, true otherwise.

Definition at line 201 of file lua_utility.cpp.

◆ CloseRobotStateTable()

void argos::CLuaUtility::CloseRobotStateTable ( lua_State *  pt_state)
static

Closes a table in the robot state.

This method expects the table itself to be at the top of the stack (-1).

Parameters
pt_stateThe Lua state.
See also
OpenRobotStateTable()

Definition at line 342 of file lua_utility.cpp.

◆ EndTable()

void argos::CLuaUtility::EndTable ( lua_State *  pt_state)
static

Adds a table to the Lua stack.

This method expects the table itself to be at the top of the stack (-1) and the table name to be a index -2.

Parameters
pt_stateThe Lua state.
See also
StartTable()

Definition at line 367 of file lua_utility.cpp.

◆ GetDeviceInstance()

template<class T >
static T* argos::CLuaUtility::GetDeviceInstance ( lua_State *  pt_state,
const std::string &  str_key 
)
inlinestatic

Returns a pointer to the instance to the wanted device.

The Lua state is stored in a table called robot. Each robot device is stored as a nested table. Each nested table has an _instance field which contains the pointer to the actual device. This function returns such pointer.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the device table.
Returns
A pointer to the instance to the wanted device.

Definition at line 380 of file lua_utility.h.

◆ LoadScript()

bool argos::CLuaUtility::LoadScript ( lua_State *  pt_state,
const std::string &  str_filename 
)
static

Loads the given Lua script.

Parameters
pt_stateThe Lua state.
str_filenameThe script file name.
Returns
false in case of errors, true otherwise.

Definition at line 181 of file lua_utility.cpp.

◆ OpenRobotStateTable()

void argos::CLuaUtility::OpenRobotStateTable ( lua_State *  pt_state,
const std::string &  str_key 
)
static

Opens a table in the robot state, creating it if it does not exist.

This method expects the "robot" table to be at -1 in the stack, and pushes the table object on the stack. To close the table call CloseRobotStateTable().

Parameters
pt_stateThe Lua state.
str_keyThe string key for the robot state table.
See also
CloseRobotStateTable()

Definition at line 326 of file lua_utility.cpp.

◆ PrintGlobals()

void argos::CLuaUtility::PrintGlobals ( CARGoSLog c_log,
lua_State *  pt_state 
)
static

Prints the global Lua symbols on the specified log.

Parameters
c_logThe output log.
pt_stateThe Lua state.
See also
LOG
LOGERR
CARGoSLogger

Definition at line 267 of file lua_utility.cpp.

◆ PrintStack()

void argos::CLuaUtility::PrintStack ( CARGoSLog c_log,
lua_State *  pt_state 
)
static

Prints the Lua stack on the specified log.

Parameters
c_logThe output log.
pt_stateThe Lua state.
See also
LOG
LOGERR
CARGoSLogger

Definition at line 282 of file lua_utility.cpp.

◆ RegisterLoggerWrapper()

void argos::CLuaUtility::RegisterLoggerWrapper ( lua_State *  pt_state)
static

Registers LOG and LOGERR in the Lua state.

After this call, in a Lua script one can use log() and logerr() to print to the ARGoS logs.

Parameters
pt_stateThe Lua state.
See also
LOG
LOGERR
CARGoSLogger

Definition at line 301 of file lua_utility.cpp.

◆ RegisterRNG()

void argos::CLuaUtility::RegisterRNG ( lua_State *  pt_state,
CRandom::CRNG pc_rng 
)
static

Registers the given random number generator in the Lua state.

Internally, it resets the passed RNG.

Parameters
pt_stateThe Lua state.
pc_rngThe random number generator.
See also
CRandom
CRandom::CRNG
CRandom::CRNG::Reset()

Definition at line 309 of file lua_utility.cpp.

◆ SetMetatable()

void argos::CLuaUtility::SetMetatable ( lua_State *  pt_state,
const std::string &  str_key 
)
static

Sets the metatable with the given string key to the table located at the top of the stack.

At the end of the execution, the stack is in the same state as it was before this function was called.

Parameters
pt_stateThe Lua state.
str_keyThe string key for the metatable.

Definition at line 374 of file lua_utility.cpp.

◆ StartTable() [1/2]

void argos::CLuaUtility::StartTable ( lua_State *  pt_state,
const std::string &  str_key 
)
static

Adds a table with the given string key to the table located at the top of the stack.

This method pushes the table key and the table itself on the stack. To close a table call EndTable().

Parameters
pt_stateThe Lua state.
str_keyThe string key for the parent table.
See also
EndTable()

Definition at line 349 of file lua_utility.cpp.

◆ StartTable() [2/2]

void argos::CLuaUtility::StartTable ( lua_State *  pt_state,
int  n_key 
)
static

Adds a table with the given numeric key to the table located at the top of the stack.

This method pushes the table key and the table itself on the stack. To close a table call EndTable().

Parameters
pt_stateThe Lua state.
n_keyThe numeric key for the parent table.
See also
EndTable()

Definition at line 358 of file lua_utility.cpp.