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.cc18
1 files changed, 15 insertions, 3 deletions
diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc
index 67b780d..c99b48b 100644
--- a/server/src/luaquerymapper.cc
+++ b/server/src/luaquerymapper.cc
@@ -26,13 +26,18 @@
*/
#include "luaquerymapper.h"
+#include <sstream>
+
static std::string loadresultstring(QueryResult &res, std::string group = "")
{
std::string s;
+ std::stringstream timestamp; timestamp << res.timestamp;
std::map< std::string, std::string >::iterator v = res.values.begin();
while(v != res.values.end()) {
- s += group + (*v).first + " = \"" + (*v).second + "\"\n";
+ s += group + (*v).first + " = {}\n";
+ s += group + (*v).first + ".value = \"" + (*v).second + "\"\n";
+ s += group + (*v).first + ".timestamp = " + timestamp.str() + "\n";
v++;
}
@@ -81,7 +86,7 @@ LUAQueryMapper::~LUAQueryMapper()
lua_close(L);
}
-std::string LUAQueryMapper::map(const std::string &mapper)
+Value LUAQueryMapper::map(const std::string &mapper)
{
int s = luaL_loadbuffer(L, mapper.c_str(), mapper.size(), "mapper");
switch(s) {
@@ -100,7 +105,14 @@ std::string LUAQueryMapper::map(const std::string &mapper)
// Run the loaded code
lua_pcall(L, 0, LUA_MULTRET, 0);
- return lua_tostring(L, lua_gettop(L));
+ Value v;
+
+ v.timestamp = lua_tointeger(L, lua_gettop(L));
+ lua_pop(L, 1);
+ v.value = lua_tostring(L, lua_gettop(L));
+ lua_pop(L, 1);
+
+ return v;
}
#ifdef TEST_LUAQUERYMAPPER