ARGoS
3
A parallel, multi-engine simulator for swarm robotics
|
00001 00008 namespace argos { 00009 class CRadians; 00010 class CVector2; 00011 class CVector3; 00012 class CQuaternion; 00013 class CColor; 00014 } 00015 00016 #include <argos3/core/utility/logging/argos_log.h> 00017 #include <argos3/core/utility/math/rng.h> 00018 00019 extern "C" { 00020 #include <lua.h> 00021 #include <lualib.h> 00022 #include <lauxlib.h> 00023 } 00024 00025 #include <string> 00026 00027 namespace argos { 00028 00029 class CLuaUtility { 00030 00031 public: 00032 00033 enum EARGoSTypes { 00034 TYPE_NORMAL = 0, 00035 TYPE_VECTOR2, 00036 TYPE_VECTOR3, 00037 TYPE_QUATERNION, 00038 TYPE_COLOR 00039 }; 00040 00041 public: 00042 00049 static bool LoadScript(lua_State* pt_state, 00050 const std::string& str_filename); 00051 00058 static bool CallLuaFunction(lua_State* pt_state, 00059 const std::string& str_function); 00060 00069 static void PrintGlobals(CARGoSLog& c_log, 00070 lua_State* pt_state); 00071 00080 static void PrintStack(CARGoSLog& c_log, 00081 lua_State* pt_state); 00082 00092 static void RegisterLoggerWrapper(lua_State* pt_state); 00093 00103 static void RegisterRNG(lua_State* pt_state, 00104 CRandom::CRNG* pc_rng); 00105 00115 static void OpenRobotStateTable(lua_State* pt_state, 00116 const std::string& str_key); 00117 00124 static void CloseRobotStateTable(lua_State* pt_state); 00125 00134 static void StartTable(lua_State* pt_state, 00135 const std::string& str_key); 00136 00145 static void StartTable(lua_State* pt_state, 00146 int n_key); 00147 00155 static void EndTable(lua_State* pt_state); 00156 00165 static void AddToTable(lua_State* pt_state, 00166 const std::string& str_key, 00167 void* pt_data); 00168 00177 static void AddToTable(lua_State* pt_state, 00178 const std::string& str_key, 00179 lua_CFunction pt_data); 00180 00189 static void AddToTable(lua_State* pt_state, 00190 const std::string& str_key, 00191 Real f_data); 00192 00201 static void AddToTable(lua_State* pt_state, 00202 int n_key, 00203 Real f_data); 00204 00213 static void AddToTable(lua_State* pt_state, 00214 const std::string& str_key, 00215 const CRadians& c_data); 00216 00225 static void AddToTable(lua_State* pt_state, 00226 int n_key, 00227 const CRadians& c_data); 00228 00239 static void AddToTable(lua_State* pt_state, 00240 const std::string& str_key, 00241 const CVector2& c_data); 00242 00253 static void AddToTable(lua_State* pt_state, 00254 int n_key, 00255 const CVector2& c_data); 00256 00267 static void AddToTable(lua_State* pt_state, 00268 const std::string& str_key, 00269 const CVector3& c_data); 00270 00281 static void AddToTable(lua_State* pt_state, 00282 int n_key, 00283 const CVector3& c_data); 00284 00295 static void AddToTable(lua_State* pt_state, 00296 const std::string& str_key, 00297 const CQuaternion& c_data); 00298 00309 static void AddToTable(lua_State* pt_state, 00310 int n_key, 00311 const CQuaternion& c_data); 00312 00323 static void AddToTable(lua_State* pt_state, 00324 const std::string& str_key, 00325 const CColor& c_data); 00326 00337 static void AddToTable(lua_State* pt_state, 00338 int n_key, 00339 const CColor& c_data); 00340 00351 template<class T> 00352 static T* GetDeviceInstance(lua_State* pt_state, 00353 const std::string& str_key) { 00354 lua_getglobal(pt_state, "robot"); 00355 lua_getfield(pt_state, -1, str_key.c_str()); 00356 lua_getfield(pt_state, -1, "_instance"); 00357 T* ptRetVal = reinterpret_cast<T*>(lua_touserdata(pt_state, -1)); 00358 lua_pop(pt_state, 3); 00359 return ptRetVal; 00360 } 00361 00362 private: 00363 00364 static int LOGWrapper(lua_State* pt_state); 00365 00366 static int LOGERRWrapper(lua_State* pt_state); 00367 00368 static int LoggerWrapper(CARGoSLog& c_log, 00369 lua_State* pt_state); 00370 00371 }; 00372 00373 } 00374