From 192e0f80bd2da45f1c612411fded2e805ac205de Mon Sep 17 00:00:00 2001 From: deva Date: Mon, 26 May 2008 13:56:30 +0000 Subject: Completed the prefilling of the fields, from the db and pentominos, according to their timestamps. --- server/src/luaquerymapper.cc | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'server/src/luaquerymapper.cc') 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 + 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 -- cgit v1.2.3