New inheritance graph code.
[luabind.git] / luabind / error.hpp
blobb282a411a563163cad4bdb857116187dbcd9a291
1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
3 // Permission is hereby granted, free of charge, to any person obtaining a
4 // copy of this software and associated documentation files (the "Software"),
5 // to deal in the Software without restriction, including without limitation
6 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
7 // and/or sell copies of the Software, and to permit persons to whom the
8 // Software is furnished to do so, subject to the following conditions:
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
14 // ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
15 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
16 // PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
17 // SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR
18 // ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
19 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
21 // OR OTHER DEALINGS IN THE SOFTWARE.
23 #ifndef LUABIND_ERROR_HPP_INCLUDED
24 #define LUABIND_ERROR_HPP_INCLUDED
26 #include <luabind/prefix.hpp>
27 #include <exception>
28 #include <luabind/config.hpp>
29 #include <luabind/typeid.hpp>
31 struct lua_State;
33 namespace luabind
36 #ifndef LUABIND_NO_EXCEPTIONS
38 // this exception usually means that the lua function you called
39 // from C++ failed with an error code. You will have to
40 // read the error code from the top of the lua stack
41 // the reason why this exception class doesn't contain
42 // the message itself is that std::string's copy constructor
43 // may throw, if the copy constructor of an exception that is
44 // being thrown throws another exception, terminate will be called
45 // and the entire application is killed.
46 class LUABIND_API error : public std::exception
48 public:
49 explicit error(lua_State* L): m_L(L) {}
50 lua_State* state() const throw() { return m_L; }
51 virtual const char* what() const throw()
53 return "lua runtime error";
55 private:
56 lua_State* m_L;
59 // if an object_cast<>() fails, this is thrown
60 // it is also thrown if the return value of
61 // a lua function cannot be converted
62 class LUABIND_API cast_failed : public std::exception
64 public:
65 cast_failed(lua_State* L, type_id const& i): m_L(L), m_info(i) {}
66 lua_State* state() const throw() { return m_L; }
67 type_id info() const throw() { return m_info; }
68 virtual const char* what() const throw() { return "unable to make cast"; }
69 private:
70 lua_State* m_L;
71 type_id m_info;
74 #else
76 typedef void(*error_callback_fun)(lua_State*);
77 typedef void(*cast_failed_callback_fun)(lua_State*, type_id const&);
79 LUABIND_API void set_error_callback(error_callback_fun e);
80 LUABIND_API void set_cast_failed_callback(cast_failed_callback_fun c);
81 LUABIND_API error_callback_fun get_error_callback();
82 LUABIND_API cast_failed_callback_fun get_cast_failed_callback();
84 #endif
86 typedef int(*pcall_callback_fun)(lua_State*);
87 LUABIND_API void set_pcall_callback(pcall_callback_fun e);
88 LUABIND_API pcall_callback_fun get_pcall_callback();
92 #endif // LUABIND_ERROR_HPP_INCLUDED