ARGoS 3
A parallel, multi-engine simulator for swarm robotics
ci_magnets_actuator.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
13namespace argos {
14
15 /****************************************/
16 /****************************************/
17
21
22 /****************************************/
23 /****************************************/
24
25#ifdef ARGOS_WITH_LUA
26 int LuaSetCurrent(lua_State* pt_lua_state) {
27 /* get a reference to the actuator */
28 CCI_MagnetsActuator::SInterface* ps_interface =
29 reinterpret_cast<CCI_MagnetsActuator::SInterface*>(lua_touserdata(pt_lua_state, lua_upvalueindex(1)));
30 /* check number of arguments */
31 if(lua_gettop(pt_lua_state) != 1) {
32 std::string strErrMsg = "robot.magnets." + ps_interface->Id + ".set_current() requires 1 argument";
33 return luaL_error(pt_lua_state, strErrMsg.c_str());
34 }
35 luaL_checktype(pt_lua_state, 1, LUA_TNUMBER);
36 /* Perform action */
37 ps_interface->Current = lua_tonumber(pt_lua_state, 1);
38 return 0;
39 }
40#endif
41
42 /****************************************/
43 /****************************************/
44
45#ifdef ARGOS_WITH_LUA
46 void CCI_MagnetsActuator::CreateLuaState(lua_State* pt_lua_state) {
47 CLuaUtility::StartTable(pt_lua_state, "magnets");
48 for(SInterface& s_interface : m_vecInterfaces) {
49 CLuaUtility::StartTable(pt_lua_state, s_interface.Id);
50 /* push a pointer to each actuator instance onto the lua stack */
51 lua_pushstring(pt_lua_state, "set_current");
52 lua_pushlightuserdata(pt_lua_state, &s_interface);
53 lua_pushcclosure(pt_lua_state, &LuaSetCurrent, 1);
54 lua_settable(pt_lua_state, -3);
55 CLuaUtility::EndTable(pt_lua_state);
56 }
57 CLuaUtility::EndTable(pt_lua_state);
58 }
59#endif
60
61
62}
The namespace containing all the ARGoS related code.
Definition ci_actuator.h:12
virtual void CreateLuaState(lua_State *pt_lua_state)=0
Creates the Lua state for this actuator.
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.
SInterface::TVector & GetInterfaces()
Returns a reference to the magnet interfaces.
SInterface::TVector m_vecInterfaces