ci_light_sensor.cpp
Go to the documentation of this file.
1 
7 #include "ci_light_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  const std::vector<Real>& CCI_LightSensor::GetReadings() const {
19  return m_tReadings;
20  }
21 
22  /****************************************/
23  /****************************************/
24 
25 #ifdef ARGOS_WITH_LUA
26  void CCI_LightSensor::CreateLuaState(lua_State* pt_lua_state) {
27  CLuaUtility::StartTable(pt_lua_state, "light");
28  for(size_t i = 0; i < m_tReadings.size(); ++i) {
29  CLuaUtility::AddToTable(pt_lua_state, i+1, m_tReadings[i]);
30  }
31  CLuaUtility::EndTable(pt_lua_state);
32  }
33 #endif
34 
35  /****************************************/
36  /****************************************/
37 
38 #ifdef ARGOS_WITH_LUA
39  void CCI_LightSensor::ReadingsToLuaState(lua_State* pt_lua_state) {
40  lua_getfield(pt_lua_state, -1, "light");
41  for(size_t i = 0; i < m_tReadings.size(); ++i) {
42  lua_pushnumber(pt_lua_state, i+1 );
43  lua_pushnumber(pt_lua_state, m_tReadings[i]);
44  lua_settable (pt_lua_state, -3 );
45  }
46  lua_pop(pt_lua_state, 1);
47  }
48 #endif
49 
50 
51  /****************************************/
52  /****************************************/
53 
54 }
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...
std::vector< Real > m_tReadings
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.
const std::vector< Real > & GetReadings() const
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.