summaryrefslogtreecommitdiff
path: root/server/src/luaquerymapper.cc
diff options
context:
space:
mode:
authordeva <deva>2008-06-04 08:16:12 +0000
committerdeva <deva>2008-06-04 08:16:12 +0000
commit294ed0c031072489f520c90e373b2f24aa16ed8c (patch)
tree5c7629db626d308a2da25389a04626eb70056150 /server/src/luaquerymapper.cc
parent39bd5c058ea842db10fc56ee153ec338e0d24f0f (diff)
Introduced the errorbox to communicate server errors to the client.
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));