summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/src/luaquerymapper.cc22
-rw-r--r--server/src/luaquerymapper.h1
-rw-r--r--server/src/server.cc19
3 files changed, 29 insertions, 13 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));
diff --git a/server/src/luaquerymapper.h b/server/src/luaquerymapper.h
index d5e03b0..83866a0 100644
--- a/server/src/luaquerymapper.h
+++ b/server/src/luaquerymapper.h
@@ -52,6 +52,7 @@ public:
private:
lua_State *L;
+ int clean_top;
};
diff --git a/server/src/server.cc b/server/src/server.cc
index a896102..9229f28 100644
--- a/server/src/server.cc
+++ b/server/src/server.cc
@@ -51,17 +51,14 @@ static std::string error_box(std::string message)
{
std::string errorbox;
- errorbox += " <course name=\"error\">\n";
- errorbox += " <macro name=\"error\">\n";
- errorbox += " <window caption=\"ERROR!\" height=\"240\" layout=\"vbox\" "
- "name=\"err\" width=\"320\">\n";
- errorbox += " <textedit name=\"errorlabel\" value=\"";
- errorbox += message;
- errorbox += "\"/>\n";
- errorbox += " <button action=\"cancel\" caption=\"Luk\" name=\"cancel\"/>\n";
- errorbox += " </window>\n";
- errorbox += " </macro>\n";
- errorbox += " </course>\n";
+ errorbox += " <course name=\"error\">\n";
+ errorbox += " <macro name=\"error\">\n";
+ errorbox += " <window caption=\"ERROR!\" height=\"240\" layout=\"vbox\" name=\"err\" width=\"320\">\n";
+ errorbox += " <textedit name=\"errorlabel\" value=\"" + message + "\"/>\n";
+ errorbox += " <button action=\"cancel\" caption=\"Luk\" name=\"cancel\"/>\n";
+ errorbox += " </window>\n";
+ errorbox += " </macro>\n";
+ errorbox += " </course>\n";
return errorbox;
}