1 // Copyright 2011 Google Inc.
2 // All rights reserved.
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
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.
34 #include "exceptions.hpp"
38 /// Constructs a new error with a plain-text message.
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.
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
) :
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.
73 /// \pre There is an error message on the top of the stack.
74 /// \post The error message is popped from the stack.
76 /// \param state_ The Lua state.
77 /// \param api_function_ The name of the Lua API function that caused the error.
79 /// \return A new api_error with the popped message.
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.
94 /// \return The name of the function.
96 lutok::api_error::api_function(void) const
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"),
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.
123 lutok::file_not_found_error::filename(void) const