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.cc22
1 files changed, 20 insertions, 2 deletions
diff --git a/server/src/luaquerymapper.cc b/server/src/luaquerymapper.cc
index b698fe9..2de1d3c 100644
--- a/server/src/luaquerymapper.cc
+++ b/server/src/luaquerymapper.cc
@@ -78,6 +78,8 @@ LUAQueryMapper::LUAQueryMapper(QueryResult &res)
// Run program (init)
lua_pcall(L, 0, LUA_MULTRET, 0);
+
+ clean_top = lua_gettop(L);
}
LUAQueryMapper::~LUAQueryMapper()
@@ -87,6 +89,14 @@ LUAQueryMapper::~LUAQueryMapper()
Value LUAQueryMapper::map(const std::string &mapper)
{
+ Value v;
+
+ if(mapper == "") {
+ printf("Empty LUA mapper detected!\n");
+ v.timestamp = 0;
+ v.value = "";
+ }
+
int s = luaL_loadbuffer(L, mapper.c_str(), mapper.size(), "mapper");
switch(s) {
case 0: //no errors;
@@ -104,8 +114,16 @@ Value LUAQueryMapper::map(const std::string &mapper)
// Run the loaded code
lua_pcall(L, 0, LUA_MULTRET, 0);
- Value v;
-
+ // Check if app messed up the stack.
+ if(lua_gettop(L) != clean_top) {
+ printf("LUA mapper messed up the stack (wrong number of return values)!\n");
+ lua_pop(L, lua_gettop(L) - clean_top);
+ Value v;
+ v.timestamp = 0;
+ v.value = "";
+ return v;
+ }
+
v.timestamp = lua_tointeger(L, lua_gettop(L));
lua_pop(L, 1);
v.value = lua_tostring(L, lua_gettop(L));