ci_camera_sensor_directional_led_detector_algorithm.cpp
Go to the documentation of this file.
1 
8 
9 #ifdef ARGOS_WITH_LUA
10 #include <argos3/core/wrappers/lua/lua_utility.h>
11 #endif
12 
13 
14 namespace argos {
15 
16  /****************************************/
17  /****************************************/
18 
19 #ifdef ARGOS_WITH_LUA
20  void CCI_CameraSensorDirectionalLEDDetectorAlgorithm::CreateLuaState(lua_State* pt_lua_state) {
21  for(size_t i = 0; i < m_vecReadings.size(); ++i) {
22  CLuaUtility::StartTable(pt_lua_state, i + 1);
23  CLuaUtility::AddToTable(pt_lua_state, "color", m_vecReadings[i].Color);
24  CLuaUtility::AddToTable(pt_lua_state, "center", m_vecReadings[i].Center);
25  CLuaUtility::EndTable(pt_lua_state);
26  }
27  }
28 #endif
29 
30  /****************************************/
31  /****************************************/
32 
33 #ifdef ARGOS_WITH_LUA
34  void CCI_CameraSensorDirectionalLEDDetectorAlgorithm::ReadingsToLuaState(lua_State* pt_lua_state) {
35  size_t unLastReadingsNum = lua_rawlen(pt_lua_state, -1);
36  for(size_t i = 0; i < m_vecReadings.size(); ++i) {
37  CLuaUtility::StartTable(pt_lua_state, i + 1);
38  CLuaUtility::AddToTable(pt_lua_state, "color", m_vecReadings[i].Color);
39  CLuaUtility::AddToTable(pt_lua_state, "center", m_vecReadings[i].Center);
40  CLuaUtility::EndTable(pt_lua_state);
41  }
42  if(m_vecReadings.size() < unLastReadingsNum) {
43  /* Remove extra readings from last update by setting them to nil */
44  for(size_t i = m_vecReadings.size() + 1; i <= unLastReadingsNum; ++i) {
45  lua_pushnumber(pt_lua_state, i);
46  lua_pushnil (pt_lua_state);
47  lua_settable (pt_lua_state, -3);
48  }
49  }
50  }
51 #endif
52 
53  /****************************************/
54  /****************************************/
55 
56 }
static void EndTable(lua_State *pt_state)
Adds a table to the Lua stack.
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.
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 st...
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12