1
0
Fork 0
mirror of https://git.rwth-aachen.de/acs/public/villas/node/ synced 2025-03-09 00:00:00 +01:00

lua: fix Lua 5.1 compatability

This commit is contained in:
Steffen Vogel 2021-03-17 10:23:03 -04:00 committed by Steffen Vogel
parent 56315a026c
commit 65e26e31b9

View file

@ -150,9 +150,11 @@ lua_tosample(lua_State *L, struct sample *smp, struct vlist *signals, bool use_n
{
int ret;
smp->length = 0;
smp->flags = 0;
ret = lua_getfield(L, idx, "sequence");
lua_getfield(L, idx, "sequence");
ret = lua_type(L, -1);
if (ret != LUA_TNIL) {
smp->sequence = lua_tonumber(L, -1);
smp->flags |= (int) SampleFlags::HAS_SEQUENCE;
@ -160,6 +162,7 @@ lua_tosample(lua_State *L, struct sample *smp, struct vlist *signals, bool use_n
lua_pop(L, 1);
lua_getfield(L, idx, "ts_origin");
ret = lua_type(L, -1);
if (ret != LUA_TNIL) {
lua_totimespec(L, &smp->ts.origin);
smp->flags |= (int) SampleFlags::HAS_TS_ORIGIN;
@ -167,6 +170,7 @@ lua_tosample(lua_State *L, struct sample *smp, struct vlist *signals, bool use_n
lua_pop(L, 1);
lua_getfield(L, idx, "ts_received");
ret = lua_type(L, -1);
if (ret != LUA_TNIL) {
lua_totimespec(L, &smp->ts.received);
smp->flags |= (int) SampleFlags::HAS_TS_RECEIVED;
@ -174,22 +178,27 @@ lua_tosample(lua_State *L, struct sample *smp, struct vlist *signals, bool use_n
lua_pop(L, 1);
lua_getfield(L, idx, "data");
for (unsigned i = 0; i < smp->length; i++) {
struct signal *sig = (struct signal *) vlist_at(signals, i);
ret = lua_type(L, -1);
if (ret != LUA_TNIL) {
for (unsigned i = 0; i < smp->length; i++) {
struct signal *sig = (struct signal *) vlist_at(signals, i);
if (use_names)
lua_getfield(L, -1, sig->name);
else
lua_rawgeti(L, -1, i);
if (use_names)
lua_getfield(L, -1, sig->name);
else
lua_rawgeti(L, -1, i);
lua_tosignaldata(L, &smp->data[i], sig->type);
ret = lua_type(L, -1);
if (ret != LUA_TNIL)
lua_tosignaldata(L, &smp->data[i], sig->type, -1);
lua_pop(L, 1);
lua_pop(L, 1);
}
if (smp->length > 0)
smp->flags |= (int) SampleFlags::HAS_DATA;
}
lua_pop(L, 1);
if (smp->length > 0)
smp->flags |= (int) SampleFlags::HAS_DATA;
}
static void
@ -429,7 +438,7 @@ LuaSignalExpression::evaluate(union signal_data *data, enum SignalType type)
lua_pop(L, 1);
}
lua_tosignaldata(L, data, type);
lua_tosignaldata(L, data, type, -1);
lua_pop(L, 1);
}