diff options
author | deva <deva> | 2010-05-07 09:31:26 +0000 |
---|---|---|
committer | deva <deva> | 2010-05-07 09:31:26 +0000 |
commit | 965e43178736e6635cf27410e6d73f4ec0fdced2 (patch) | |
tree | 7cc297f68e93f6974baaf185259ac88f35df0355 /server/src/luaresume.cc | |
parent | 3241d29dec9beb0c367340465bd8d9bcab863692 (diff) |
LOTS of changes. libmicrohttpd fix for 'chunked' POST handling and LUA parameter checker from Pentominos among other things.
Diffstat (limited to 'server/src/luaresume.cc')
-rw-r--r-- | server/src/luaresume.cc | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/server/src/luaresume.cc b/server/src/luaresume.cc index 8ba5641..099c3bd 100644 --- a/server/src/luaresume.cc +++ b/server/src/luaresume.cc @@ -26,6 +26,8 @@ */ #include "luaresume.h" +#include "luautil.h" + #include "debug.h" #include <stdio.h> @@ -34,14 +36,9 @@ static int _getValue(lua_State *L) { - int n = lua_gettop(L); // number of arguments - if(n != 1) { - char errstr[512]; - sprintf(errstr, "Number of args expected 0, got %d", n); - lua_pushstring(L, errstr); - lua_error(L); - return 1; - } + Pracro::checkParameters(L, + Pracro::T_STRING, + Pracro::T_END); std::string name = lua_tostring(L, lua_gettop(L)); @@ -65,7 +62,7 @@ LUAResume::LUAResume(Commit &c) { L = luaL_newstate(); if(L == NULL) { - error("Could not create LUA state."); + PRACRO_ERR(luaresume, "Could not create LUA state.\n"); return; } @@ -85,7 +82,7 @@ LUAResume::~LUAResume() std::string LUAResume::getValue(std::string name) { if(commit.fields.find(name) == commit.fields.end()) { - error("LUAResume: No such field '" + name + "'"); + PRACRO_ERR(luaresume, "LUAResume: No such field '%s'\n", name.c_str()); return ""; } @@ -95,11 +92,11 @@ std::string LUAResume::getValue(std::string name) std::string LUAResume::run(std::string program) { if(L == NULL) { - error("LUA state not initialized!"); + PRACRO_ERR(luaresume, "LUA state not initialized!"); return false; } - PRACRO_DEBUG(lua, "Running %s\n", program.c_str()); + PRACRO_DEBUG(luaresume, "Running %s\n", program.c_str()); /* lua_pushstring(L, value.toStdString().c_str()); @@ -111,24 +108,25 @@ std::string LUAResume::run(std::string program) int top = lua_gettop(L); - if(luaL_loadbuffer(L, program.c_str(), program.size(), "lua resume generator")) { - error(lua_tostring(L, lua_gettop(L))); + if(luaL_loadbuffer(L, program.c_str(), program.size(), + "lua resume generator")) { + PRACRO_ERR(luaresume, "loadbufer: %s\n", lua_tostring(L, lua_gettop(L))); return false; } // Run the loaded code if(lua_pcall(L, 0, LUA_MULTRET, 0)) { - error(lua_tostring(L, lua_gettop(L))); + PRACRO_ERR(luaresume, "pcall: %s\n" , lua_tostring(L, lua_gettop(L))); return false; } if(top != lua_gettop(L) - 1) { - error("Program did not return a single value.\n"); + PRACRO_ERR(luaresume, "Program did not return a single value.\n"); return false; } if(lua_isstring(L, lua_gettop(L)) == false) { - error("Program did not return a string value.\n"); + PRACRO_ERR(luaresume, "Program did not return a string value.\n"); return false; } @@ -140,5 +138,5 @@ std::string LUAResume::run(std::string program) void LUAResume::error(std::string message) { - printf("LUA ERROR: %s\n", message.c_str()); + PRACRO_ERR(luaresume, "LUA ERROR: %s\n", message.c_str()); } |