35 #define LUA_PUSHT_INT(l, k, v) do { \
36 lua_pushliteral(luastate, k); \
37 lua_pushinteger(luastate, v); \
38 lua_settable(luastate, -3); \
47 lua_pushinteger(luastate, i++);
48 lua_newtable(luastate);
50 lua_pushliteral(luastate,
"index");
51 lua_pushinteger(luastate, point->
index);
52 lua_settable(luastate, -3);
56 lua_settable(luastate, -3);
60 static void DNP3PushObjects(
lua_State *luastate, DNP3ObjectList *objects)
66 lua_pushinteger(luastate, i++);
67 lua_newtable(luastate);
69 lua_pushliteral(luastate,
"group");
70 lua_pushinteger(luastate, object->
group);
71 lua_settable(luastate, -3);
73 lua_pushliteral(luastate,
"variation");
74 lua_pushinteger(luastate, object->
variation);
75 lua_settable(luastate, -3);
77 lua_pushliteral(luastate,
"points");
78 lua_newtable(luastate);
79 DNP3PushPoints(luastate,
object);
80 lua_settable(luastate, -3);
82 lua_settable(luastate, -3);
86 static void DNP3PushLinkHeader(
lua_State *luastate, DNP3LinkHeader *header)
95 static void DNP3PushApplicationHeader(
lua_State *luastate,
96 DNP3ApplicationHeader *header)
99 LUA_PUSHT_INT(luastate,
"function_code", header->function_code);
105 lua_pushliteral(luastate,
"link_header");
106 lua_newtable(luastate);
107 DNP3PushLinkHeader(luastate, &tx->
lh);
108 lua_settable(luastate, -3);
114 lua_pushliteral(luastate,
"application_header");
115 lua_newtable(luastate);
116 DNP3PushApplicationHeader(luastate, &tx->
ah);
117 lua_settable(luastate, -3);
119 lua_pushliteral(luastate,
"objects");
120 lua_newtable(luastate);
121 DNP3PushObjects(luastate, &tx->
objects);
122 lua_settable(luastate, -3);
128 lua_pushliteral(luastate,
"link_header");
129 lua_newtable(luastate);
130 DNP3PushLinkHeader(luastate, &tx->
lh);
131 lua_settable(luastate, -3);
137 lua_pushliteral(luastate,
"application_header");
138 lua_newtable(luastate);
139 DNP3PushApplicationHeader(luastate, &tx->
ah);
140 lua_settable(luastate, -3);
145 lua_pushliteral(luastate,
"objects");
146 lua_newtable(luastate);
147 DNP3PushObjects(luastate, &tx->
objects);
148 lua_settable(luastate, -3);
151 static int DNP3GetTx(
lua_State *luastate)
162 lua_newtable(luastate);
164 lua_pushliteral(luastate,
"tx_num");
165 lua_pushinteger(luastate, tx->
tx_num);
166 lua_settable(luastate, -3);
170 lua_pushliteral(luastate,
"request");
171 lua_newtable(luastate);
174 DNP3PushRequest(luastate, tx);
175 lua_settable(luastate, -3);
180 lua_pushliteral(luastate,
"response");
181 lua_newtable(luastate);
184 DNP3PushResponse(luastate, tx);
185 lua_settable(luastate, -3);
193 lua_pushcfunction(luastate, DNP3GetTx);
194 lua_setglobal(luastate,
"DNP3GetTx");