ci_ground_sensor.cpp
Go to the documentation of this file.
1 
7 #include "ci_ground_sensor.h"
8 
9 #ifdef ARGOS_WITH_LUA
10 #include <argos3/core/wrappers/lua/lua_utility.h>
11 #endif
12 
13 namespace argos {
14 
15  /****************************************/
16  /****************************************/
17 
18 #ifdef ARGOS_WITH_LUA
19  void CCI_GroundSensor::CreateLuaState(lua_State* pt_lua_state) {
20  CLuaUtility::StartTable(pt_lua_state, "ground");
21  for(size_t i = 0; i < m_tReadings.size(); ++i) {
22  CLuaUtility::AddToTable(pt_lua_state, i+1, m_tReadings[i]);
23  }
24  CLuaUtility::EndTable(pt_lua_state);
25  }
26 #endif
27 
28  /****************************************/
29  /****************************************/
30 
31 #ifdef ARGOS_WITH_LUA
32  void CCI_GroundSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
33  lua_getfield(pt_lua_state, -1, "ground");
34  for(size_t i = 0; i < m_tReadings.size(); ++i) {
35  lua_pushnumber(pt_lua_state, i+1 );
36  lua_pushnumber(pt_lua_state, m_tReadings[i]);
37  lua_settable (pt_lua_state, -3 );
38  }
39  lua_pop(pt_lua_state, 1);
40  }
41 #endif
42 
43 
44  /****************************************/
45  /****************************************/
46 
47  const std::vector<Real>& CCI_GroundSensor::GetReadings() const {
48  return m_tReadings;
49  }
50 
51  /****************************************/
52  /****************************************/
53 
54 }
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
static void EndTable(lua_State *pt_state)
Adds a table to the Lua 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...
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.
std::vector< Real > m_tReadings
const std::vector< Real > & GetReadings() const