comparison Core/Lua/LuaContext.cpp @ 1583:9ea3d082b064

got rid of custom exceptions
author Sebastien Jodogne <s.jodogne@gmail.com>
date Tue, 25 Aug 2015 17:52:50 +0200
parents 33d34bc4ac15
children f2e3d030ea59
comparison
equal deleted inserted replaced
1582:bd1889029cbb 1583:9ea3d082b064
32 32
33 #include "../PrecompiledHeaders.h" 33 #include "../PrecompiledHeaders.h"
34 #include "LuaContext.h" 34 #include "LuaContext.h"
35 35
36 #include "../Logging.h" 36 #include "../Logging.h"
37 #include "../OrthancException.h"
37 38
38 #include <set> 39 #include <set>
39 #include <cassert> 40 #include <cassert>
40 #include <boost/lexical_cast.hpp> 41 #include <boost/lexical_cast.hpp>
41 42
367 lua_rawset(lua_, -3); 368 lua_rawset(lua_, -3);
368 } 369 }
369 } 370 }
370 else 371 else
371 { 372 {
372 throw LuaException("Unsupported JSON conversion"); 373 throw OrthancException(ErrorCode_JsonToLuaTable);
373 } 374 }
374 } 375 }
375 376
376 377
377 void LuaContext::GetJson(Json::Value& result, 378 void LuaContext::GetJson(Json::Value& result,
482 LuaContext::LuaContext() 483 LuaContext::LuaContext()
483 { 484 {
484 lua_ = luaL_newstate(); 485 lua_ = luaL_newstate();
485 if (!lua_) 486 if (!lua_)
486 { 487 {
487 throw LuaException("Unable to create the Lua context"); 488 throw OrthancException(ErrorCode_CannotCreateLua);
488 } 489 }
489 490
490 luaL_openlibs(lua_); 491 luaL_openlibs(lua_);
491 lua_register(lua_, "print", PrintToLog); 492 lua_register(lua_, "print", PrintToLog);
492 lua_register(lua_, "ParseJson", ParseJson); 493 lua_register(lua_, "ParseJson", ParseJson);
519 assert(lua_gettop(lua_) >= 1); 520 assert(lua_gettop(lua_) >= 1);
520 521
521 std::string description(lua_tostring(lua_, -1)); 522 std::string description(lua_tostring(lua_, -1));
522 lua_pop(lua_, 1); /* pop error message from the stack */ 523 lua_pop(lua_, 1); /* pop error message from the stack */
523 LOG(ERROR) << "Error while executing Lua script: " << description; 524 LOG(ERROR) << "Error while executing Lua script: " << description;
524 throw LuaException(description); 525 throw OrthancException(ErrorCode_CannotExecuteLua);
525 } 526 }
526 527
527 if (output != NULL) 528 if (output != NULL)
528 { 529 {
529 *output = log_; 530 *output = log_;