summaryrefslogtreecommitdiff
path: root/server/src/luaformatmapper.cc
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/luaformatmapper.cc')
-rw-r--r--server/src/luaformatmapper.cc16
1 files changed, 13 insertions, 3 deletions
diff --git a/server/src/luaformatmapper.cc b/server/src/luaformatmapper.cc
index b45c170..6c0115d 100644
--- a/server/src/luaformatmapper.cc
+++ b/server/src/luaformatmapper.cc
@@ -30,6 +30,8 @@
#include "exception.h"
+#include "luaformatmapperutils.h"
+
static std::string loadresultstring(Fields &fields)
{
std::string s;
@@ -53,6 +55,9 @@ LUAFormatMapper::LUAFormatMapper(Fields &fields)
luaL_openlibs(L);
+ setGlobal(L, "LUAFormatMapper", this);
+ preload_formatutils(L);
+
std::string preload = loadresultstring(fields);
if(luaL_loadbuffer(L, preload.c_str(), preload.size(), "preload")) {
@@ -101,14 +106,14 @@ std::string LUAFormatMapper::map(const std::string &mapper)
}
// Check if app messed up the stack.
- if(lua_gettop(L) != clean_top + 1) {
+ if(lua_gettop(L) != clean_top) {
error("Wrong number of return values in " + mapper);
lua_pop(L, lua_gettop(L) - clean_top);
return output;
}
- output = lua_tostring(L, lua_gettop(L));
- lua_pop(L, 1);
+ // output = lua_tostring(L, lua_gettop(L));
+ // lua_pop(L, 1);
return output;
}
@@ -117,3 +122,8 @@ void LUAFormatMapper::error(std::string message)
{
throw Exception("ERROR in LUAFormatMapper: " + message);
}
+
+void LUAFormatMapper::bufferoutput(std::string value)
+{
+ output += value;
+}