10 #include <argos3/core/wrappers/lua/lua_utility.h>
26 int LuaSendData(lua_State* pt_lua_state) {
31 if(lua_gettop(pt_lua_state) != 1) {
32 std::string strErrMsg =
"robot.radios." + ps_interface->
Id +
".tx_data() requires 1 argument";
33 return luaL_error(pt_lua_state, strErrMsg.c_str());
35 luaL_checktype(pt_lua_state, 1, LUA_TTABLE);
37 CByteArray cBuffer(lua_rawlen(pt_lua_state, -1));
38 for(
size_t i = 0; i < cBuffer.Size(); ++i) {
39 lua_pushnumber(pt_lua_state, i + 1);
40 lua_gettable(pt_lua_state, -2);
41 if(lua_type(pt_lua_state, -1) == LUA_TNUMBER) {
42 cBuffer[i] =
static_cast<UInt8>(lua_tonumber(pt_lua_state, -1));
43 lua_pop(pt_lua_state, 1);
46 return luaL_error(pt_lua_state,
"element #%d of the table is not a number", i + 1);
49 ps_interface->
Data.emplace_back(cBuffer);
58 void CCI_RadiosActuator::CreateLuaState(lua_State* pt_lua_state) {
63 lua_pushstring(pt_lua_state,
"tx_data");
64 lua_pushlightuserdata(pt_lua_state, &s_interface);
65 lua_pushcclosure(pt_lua_state, &LuaSendData, 1);
66 lua_settable(pt_lua_state, -3);
unsigned char UInt8
8-bit unsigned integer.
The namespace containing all the ARGoS related code.
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 m_vecInterfaces
SInterface::TVector & GetInterfaces()
Returns a reference to the radio interfaces.
std::vector< SInterface > TVector
std::vector< CByteArray > Data