37 #define LUA_PUSHT_INT(l, k, v) do { \
38 lua_pushliteral(luastate, k); \
39 lua_pushinteger(luastate, v); \
40 lua_settable(luastate, -3); \
49 lua_pushinteger(luastate, i++);
50 lua_newtable(luastate);
52 lua_pushliteral(luastate,
"index");
53 lua_pushinteger(luastate, point->
index);
54 lua_settable(luastate, -3);
58 lua_settable(luastate, -3);
62 static void DNP3PushObjects(
lua_State *luastate, DNP3ObjectList *objects)
68 lua_pushinteger(luastate, i++);
69 lua_newtable(luastate);
71 lua_pushliteral(luastate,
"group");
72 lua_pushinteger(luastate, object->
group);
73 lua_settable(luastate, -3);
75 lua_pushliteral(luastate,
"variation");
76 lua_pushinteger(luastate, object->
variation);
77 lua_settable(luastate, -3);
79 lua_pushliteral(luastate,
"points");
80 lua_newtable(luastate);
81 DNP3PushPoints(luastate,
object);
82 lua_settable(luastate, -3);
84 lua_settable(luastate, -3);
88 static void DNP3PushLinkHeader(
lua_State *luastate, DNP3LinkHeader *header)
90 LUA_PUSHT_INT(luastate,
"len", header->len);
91 LUA_PUSHT_INT(luastate,
"control", header->control);
92 LUA_PUSHT_INT(luastate,
"dst", header->dst);
93 LUA_PUSHT_INT(luastate,
"src", header->src);
94 LUA_PUSHT_INT(luastate,
"crc", header->crc);
97 static void DNP3PushApplicationHeader(
lua_State *luastate,
98 DNP3ApplicationHeader *header)
100 LUA_PUSHT_INT(luastate,
"control", header->control);
101 LUA_PUSHT_INT(luastate,
"function_code", header->function_code);
107 lua_pushliteral(luastate,
"link_header");
108 lua_newtable(luastate);
109 DNP3PushLinkHeader(luastate, &tx->
request_lh);
110 lua_settable(luastate, -3);
113 LUA_PUSHT_INT(luastate,
"transport_header", tx->
request_th);
116 lua_pushliteral(luastate,
"application_header");
117 lua_newtable(luastate);
118 DNP3PushApplicationHeader(luastate, &tx->
request_ah);
119 lua_settable(luastate, -3);
121 lua_pushliteral(luastate,
"objects");
122 lua_newtable(luastate);
124 lua_settable(luastate, -3);
130 lua_pushliteral(luastate,
"link_header");
131 lua_newtable(luastate);
133 lua_settable(luastate, -3);
136 LUA_PUSHT_INT(luastate,
"transport_header", tx->
response_th);
139 lua_pushliteral(luastate,
"application_header");
140 lua_newtable(luastate);
141 DNP3PushApplicationHeader(luastate, &tx->
response_ah);
142 lua_settable(luastate, -3);
145 LUA_PUSHT_INT(luastate,
"indicators",
148 lua_pushliteral(luastate,
"objects");
149 lua_newtable(luastate);
151 lua_settable(luastate, -3);
154 static int DNP3GetTx(
lua_State *luastate)
157 return LuaCallbackError(luastate,
"error: protocol not dnp3");
162 return LuaCallbackError(luastate,
"error: no tx");
165 lua_newtable(luastate);
167 lua_pushliteral(luastate,
"tx_num");
168 lua_pushinteger(luastate, tx->
tx_num);
169 lua_settable(luastate, -3);
171 LUA_PUSHT_INT(luastate,
"has_request", tx->
has_request);
173 lua_pushliteral(luastate,
"request");
174 lua_newtable(luastate);
177 DNP3PushRequest(luastate, tx);
178 lua_settable(luastate, -3);
181 LUA_PUSHT_INT(luastate,
"has_response", tx->
has_response);
183 lua_pushliteral(luastate,
"response");
184 lua_newtable(luastate);
187 DNP3PushResponse(luastate, tx);
188 lua_settable(luastate, -3);
194 int LuaRegisterDNP3Functions(
lua_State *luastate)
196 lua_pushcfunction(luastate, DNP3GetTx);
197 lua_setglobal(luastate,
"DNP3GetTx");