35 #define LUA_PUSHT_INT(l, k, v) do { \
36 lua_pushliteral(luastate, k); \
37 lua_pushinteger(luastate, v); \
38 lua_settable(luastate, -3); \
41 static void SCLuaPushTableBoolean(
lua_State *L,
const char *key,
bool val)
43 lua_pushstring(L, key);
44 lua_pushboolean(L, val);
54 lua_pushinteger(luastate, i++);
55 lua_newtable(luastate);
57 lua_pushliteral(luastate,
"index");
58 lua_pushinteger(luastate, point->
index);
59 lua_settable(luastate, -3);
63 lua_settable(luastate, -3);
67 static void DNP3PushObjects(
lua_State *luastate, DNP3ObjectList *objects)
73 lua_pushinteger(luastate, i++);
74 lua_newtable(luastate);
76 lua_pushliteral(luastate,
"group");
77 lua_pushinteger(luastate, object->
group);
78 lua_settable(luastate, -3);
80 lua_pushliteral(luastate,
"variation");
81 lua_pushinteger(luastate, object->
variation);
82 lua_settable(luastate, -3);
84 lua_pushliteral(luastate,
"points");
85 lua_newtable(luastate);
86 DNP3PushPoints(luastate,
object);
87 lua_settable(luastate, -3);
89 lua_settable(luastate, -3);
93 static void DNP3PushLinkHeader(
lua_State *luastate, DNP3LinkHeader *header)
102 static void DNP3PushApplicationHeader(
lua_State *luastate,
103 DNP3ApplicationHeader *header)
106 LUA_PUSHT_INT(luastate,
"function_code", header->function_code);
112 lua_pushliteral(luastate,
"link_header");
113 lua_newtable(luastate);
114 DNP3PushLinkHeader(luastate, &tx->
lh);
115 lua_settable(luastate, -3);
121 lua_pushliteral(luastate,
"application_header");
122 lua_newtable(luastate);
123 DNP3PushApplicationHeader(luastate, &tx->
ah);
124 lua_settable(luastate, -3);
126 lua_pushliteral(luastate,
"objects");
127 lua_newtable(luastate);
128 DNP3PushObjects(luastate, &tx->
objects);
129 lua_settable(luastate, -3);
135 lua_pushliteral(luastate,
"link_header");
136 lua_newtable(luastate);
137 DNP3PushLinkHeader(luastate, &tx->
lh);
138 lua_settable(luastate, -3);
144 lua_pushliteral(luastate,
"application_header");
145 lua_newtable(luastate);
146 DNP3PushApplicationHeader(luastate, &tx->
ah);
147 lua_settable(luastate, -3);
152 lua_pushliteral(luastate,
"objects");
153 lua_newtable(luastate);
154 DNP3PushObjects(luastate, &tx->
objects);
155 lua_settable(luastate, -3);
158 static int DNP3GetTx(
lua_State *luastate)
169 lua_newtable(luastate);
171 lua_pushliteral(luastate,
"tx_num");
172 lua_pushinteger(luastate, tx->
tx_num);
173 lua_settable(luastate, -3);
175 SCLuaPushTableBoolean(luastate,
"is_request", tx->
is_request);
177 lua_pushliteral(luastate,
"request");
178 lua_newtable(luastate);
179 SCLuaPushTableBoolean(luastate,
"done", tx->
done);
180 SCLuaPushTableBoolean(luastate,
"complete", tx->
complete);
181 DNP3PushRequest(luastate, tx);
182 lua_settable(luastate, -3);
184 lua_pushliteral(luastate,
"response");
185 lua_newtable(luastate);
186 SCLuaPushTableBoolean(luastate,
"done", tx->
done);
187 SCLuaPushTableBoolean(luastate,
"complete", tx->
complete);
188 DNP3PushResponse(luastate, tx);
189 lua_settable(luastate, -3);
195 static const struct luaL_Reg dnp3lib[] = {
197 {
"get_tx", DNP3GetTx, },
204 luaL_newlib(L, dnp3lib);