diff options
Diffstat (limited to 'server/src/luaresume.cc')
-rw-r--r-- | server/src/luaresume.cc | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/server/src/luaresume.cc b/server/src/luaresume.cc index b7e7348..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,7 +92,7 @@ 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; } @@ -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; } |