From 294ed0c031072489f520c90e373b2f24aa16ed8c Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 4 Jun 2008 08:16:12 +0000 Subject: Introduced the errorbox to communicate server errors to the client. --- server/src/luaquerymapper.cc | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'server/src/luaquerymapper.cc') 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)); -- cgit v1.2.3