summaryrefslogtreecommitdiff
path: root/server/src/luaquerymapper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/luaquerymapper.cc')
-rw-r--r--server/src/luaquerymapper.cc21
1 files changed, 20 insertions, 1 deletions
diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc
index 9f8293d..6a7282f 100644
--- a/server/src/luaquerymapper.cc
+++ b/server/src/luaquerymapper.cc
@@ -40,6 +40,7 @@ static std::string loadresultstring(QueryResult &res, std::string group = "")
s += group + (*v).first + " = {}\n";
s += group + (*v).first + ".value = \"" + (*v).second + "\"\n";
s += group + (*v).first + ".timestamp = " + timestamp.str() + "\n";
+ s += group + (*v).first + ".source = \"" + res.source + "\"\n";
v++;
}
@@ -75,6 +76,9 @@ void LUAQueryMapper::addQueryResult(QueryResult &result)
{
std::string preload = loadresultstring(result);
+ printf("Preload:\n%s\n", preload.c_str());
+
+
if(luaL_loadbuffer(L, preload.c_str(), preload.size(), "preload")) {
error(lua_tostring(L, lua_gettop(L)));
return;
@@ -103,6 +107,8 @@ Value LUAQueryMapper::map(const std::string &mapper)
return v;
}
+ printf("Mapper: %s\n", mapper.c_str());
+
// Load the mapper
if(luaL_loadbuffer(L, mapper.c_str(), mapper.size(), "mapper")) {
error(lua_tostring(L, lua_gettop(L)) + std::string(" in ") + mapper);
@@ -116,12 +122,23 @@ Value LUAQueryMapper::map(const std::string &mapper)
}
// Check if app messed up the stack.
- if(lua_gettop(L) != clean_top + 2) {
+ if(lua_gettop(L) != clean_top + 3) {
error("Wrong number of return values in " + mapper);
lua_pop(L, lua_gettop(L) - clean_top);
return v;
}
+ // value, timestamp, source
+
+ // Check if the types are right
+ if(lua_isstring(L, lua_gettop(L)) == false) {
+ error("Source is not a string in " + mapper);
+ lua_pop(L, 3);
+ return v;
+ }
+ v.source = lua_tostring(L, lua_gettop(L));
+ lua_pop(L, 1);
+
// Check if the types are right
if(lua_isnumber(L, lua_gettop(L)) == false) {
error("Timestamp is not an integer in " + mapper);
@@ -140,6 +157,8 @@ Value LUAQueryMapper::map(const std::string &mapper)
v.value = lua_tostring(L, lua_gettop(L));
lua_pop(L, 1);
+ printf("Result: value=%s, src=%s, time=%d\n", v.value.c_str(), v.source.c_str(), (int)v.timestamp);
+
return v;
}