Warning: include(php/utility.php): Failed to open stream: No such file or directory in /home/argos/argos3/doc/api/embedded/a00166.php on line 2

Warning: include(): Failed opening 'php/utility.php' for inclusion (include_path='.:/usr/lib64/php') in /home/argos/argos3/doc/api/embedded/a00166.php on line 2
The ARGoS Website

argos::CLuaUtility Class Reference

#include <lua_utility.h>

Public Types

enum  EARGoSTypes {
  TYPE_NORMAL = 0, TYPE_VECTOR2, TYPE_VECTOR3, TYPE_QUATERNION,
  TYPE_COLOR
}
 

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 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, 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, 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, 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 Enumeration Documentation

Enumerator
TYPE_NORMAL 
TYPE_VECTOR2 
TYPE_VECTOR3 
TYPE_QUATERNION 
TYPE_COLOR 

Definition at line 35 of file lua_utility.h.

Member Function Documentation

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 337 of file lua_utility.cpp.

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 348 of file lua_utility.cpp.

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 359 of file lua_utility.cpp.

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 370 of file lua_utility.cpp.

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 381 of file lua_utility.cpp.

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 392 of file lua_utility.cpp.

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 403 of file lua_utility.cpp.

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 414 of file lua_utility.cpp.

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 427 of file lua_utility.cpp.

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 440 of file lua_utility.cpp.

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 454 of file lua_utility.cpp.

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 468 of file lua_utility.cpp.

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 484 of file lua_utility.cpp.

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 500 of file lua_utility.cpp.

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 514 of file lua_utility.cpp.

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 175 of file lua_utility.cpp.

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 305 of file lua_utility.cpp.

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 330 of file lua_utility.cpp.

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 365 of file lua_utility.h.

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 161 of file lua_utility.cpp.

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 289 of file lua_utility.cpp.

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 231 of file lua_utility.cpp.

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 246 of file lua_utility.cpp.

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 265 of file lua_utility.cpp.

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 273 of file lua_utility.cpp.

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 312 of file lua_utility.cpp.

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 321 of file lua_utility.cpp.