Remove building with NOCRYPTO option
[minix.git] / external / bsd / lutok / dist / exceptions.cpp
blob2b1c968f3f34894ceaafae6e5e3661281aae17c4
1 // Copyright 2011 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 #include <cassert>
31 #include <lua.hpp>
33 #include "c_gate.hpp"
34 #include "exceptions.hpp"
35 #include "state.ipp"
38 /// Constructs a new error with a plain-text message.
39 ///
40 /// \param message The plain-text error message.
41 lutok::error::error(const std::string& message) :
42 std::runtime_error(message)
47 /// Destructor for the error.
48 lutok::error::~error(void) throw()
53 /// Constructs a new error.
54 ///
55 /// \param api_function_ The name of the API function that caused the error.
56 /// \param message The plain-text error message provided by Lua.
57 lutok::api_error::api_error(const std::string& api_function_,
58 const std::string& message) :
59 error(message),
60 _api_function(api_function_)
65 /// Destructor for the error.
66 lutok::api_error::~api_error(void) throw()
71 /// Constructs a new api_error with the message on the top of the Lua stack.
72 ///
73 /// \pre There is an error message on the top of the stack.
74 /// \post The error message is popped from the stack.
75 ///
76 /// \param state_ The Lua state.
77 /// \param api_function_ The name of the Lua API function that caused the error.
78 ///
79 /// \return A new api_error with the popped message.
80 lutok::api_error
81 lutok::api_error::from_stack(state& state_, const std::string& api_function_)
83 lua_State* raw_state = lutok::state_c_gate(state_).c_state();
85 assert(lua_isstring(raw_state, -1));
86 const std::string message = lua_tostring(raw_state, -1);
87 lua_pop(raw_state, 1);
88 return lutok::api_error(api_function_, message);
92 /// Gets the name of the Lua API function that caused this error.
93 ///
94 /// \return The name of the function.
95 const std::string&
96 lutok::api_error::api_function(void) const
98 return _api_function;
102 /// Constructs a new error.
104 /// \param filename_ The file that count not be found.
105 lutok::file_not_found_error::file_not_found_error(
106 const std::string& filename_) :
107 error("File '" + filename_ + "' not found"),
108 _filename(filename_)
113 /// Destructor for the error.
114 lutok::file_not_found_error::~file_not_found_error(void) throw()
119 /// Gets the name of the file that could not be found.
121 /// \return The name of the file.
122 const std::string&
123 lutok::file_not_found_error::filename(void) const
125 return _filename;