Mercurial > hg > orthanc
comparison Core/Lua/LuaFunctionCall.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 | f967bdf8534e |
children | 54bafe0e7e7b |
comparison
equal
deleted
inserted
replaced
1582:bd1889029cbb | 1583:9ea3d082b064 |
---|---|
31 | 31 |
32 | 32 |
33 #include "../PrecompiledHeaders.h" | 33 #include "../PrecompiledHeaders.h" |
34 #include "LuaFunctionCall.h" | 34 #include "LuaFunctionCall.h" |
35 | 35 |
36 #include "../OrthancException.h" | |
37 #include "../Logging.h" | |
38 | |
36 #include <cassert> | 39 #include <cassert> |
37 #include <stdio.h> | 40 #include <stdio.h> |
38 #include <boost/lexical_cast.hpp> | 41 #include <boost/lexical_cast.hpp> |
39 | 42 |
40 namespace Orthanc | 43 namespace Orthanc |
41 { | 44 { |
42 void LuaFunctionCall::CheckAlreadyExecuted() | 45 void LuaFunctionCall::CheckAlreadyExecuted() |
43 { | 46 { |
44 if (isExecuted_) | 47 if (isExecuted_) |
45 { | 48 { |
46 throw LuaException("Arguments cannot be pushed after the function is executed"); | 49 throw OrthancException(ErrorCode_LuaAlreadyExecuted); |
47 } | 50 } |
48 } | 51 } |
49 | 52 |
50 LuaFunctionCall::LuaFunctionCall(LuaContext& context, | 53 LuaFunctionCall::LuaFunctionCall(LuaContext& context, |
51 const char* functionName) : | 54 const char* functionName) : |
99 { | 102 { |
100 assert(lua_gettop(context_.lua_) >= 1); | 103 assert(lua_gettop(context_.lua_) >= 1); |
101 | 104 |
102 std::string description(lua_tostring(context_.lua_, -1)); | 105 std::string description(lua_tostring(context_.lua_, -1)); |
103 lua_pop(context_.lua_, 1); /* pop error message from the stack */ | 106 lua_pop(context_.lua_, 1); /* pop error message from the stack */ |
104 throw LuaException(description); | 107 LOG(ERROR) << description; |
108 | |
109 throw OrthancException(ErrorCode_CannotExecuteLua); | |
105 } | 110 } |
106 | 111 |
107 if (lua_gettop(context_.lua_) < numOutputs) | 112 if (lua_gettop(context_.lua_) < numOutputs) |
108 { | 113 { |
109 throw LuaException("The function does not give the expected number of outputs"); | 114 throw OrthancException(ErrorCode_LuaBadOutput); |
110 } | 115 } |
111 | 116 |
112 isExecuted_ = true; | 117 isExecuted_ = true; |
113 } | 118 } |
114 | 119 |
116 { | 121 { |
117 ExecuteInternal(1); | 122 ExecuteInternal(1); |
118 | 123 |
119 if (!lua_isboolean(context_.lua_, 1)) | 124 if (!lua_isboolean(context_.lua_, 1)) |
120 { | 125 { |
121 throw LuaException("The function is not a predicate (only true/false outputs allowed)"); | 126 throw OrthancException(ErrorCode_NotLuaPredicate); |
122 } | 127 } |
123 | 128 |
124 return lua_toboolean(context_.lua_, 1) != 0; | 129 return lua_toboolean(context_.lua_, 1) != 0; |
125 } | 130 } |
126 | 131 |
141 { | 146 { |
142 result = lua_tostring(context_.lua_, top); | 147 result = lua_tostring(context_.lua_, top); |
143 } | 148 } |
144 else | 149 else |
145 { | 150 { |
146 throw LuaException("The function does not return a string"); | 151 throw OrthancException(ErrorCode_LuaReturnsNoString); |
147 } | 152 } |
148 } | 153 } |
149 } | 154 } |