OSDN Git Service

build moflib1.0 on cmake-base system
[moflib/moflib.git] / extlib / luabind-0.8 / luabind / error.hpp
1 // Copyright (c) 2003 Daniel Wallin and Arvid Norberg
2
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:
9
10 // The above copyright notice and this permission notice shall be included
11 // in all copies or substantial portions of the Software.
12
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.
22
23 #ifndef LUABIND_ERROR_HPP_INCLUDED
24 #define LUABIND_ERROR_HPP_INCLUDED
25
26 #include <luabind/prefix.hpp>
27 #include <exception>
28 #include <luabind/config.hpp>
29
30 struct lua_State;
31
32 namespace luabind
33 {
34
35 #ifndef LUABIND_NO_EXCEPTIONS
36
37         // this exception usually means that the lua function you called
38         // from C++ failed with an error code. You will have to
39         // read the error code from the top of the lua stack
40         // the reason why this exception class doesn't contain
41         // the message itself is that std::string's copy constructor
42         // may throw, if the copy constructor of an exception that is
43         // being thrown throws another exception, terminate will be called
44         // and the entire application is killed.
45         class LUABIND_API error : public std::exception
46         {
47         public:
48                 explicit error(lua_State* L): m_L(L) {}
49                 lua_State* state() const throw() { return m_L; }
50                 virtual const char* what() const throw()
51                 {
52                         return "lua runtime error";
53                 }
54         private:
55                 lua_State* m_L;
56         };
57
58         // if an object_cast<>() fails, this is thrown
59         // it is also thrown if the return value of
60         // a lua function cannot be converted
61         class LUABIND_API cast_failed : public std::exception
62         {
63         public:
64                 cast_failed(lua_State* L, LUABIND_TYPE_INFO i): m_L(L), m_info(i) {}
65                 lua_State* state() const throw() { return m_L; }
66                 LUABIND_TYPE_INFO info() const throw() { return m_info; }
67                 virtual const char* what() const throw() { return "unable to make cast"; }
68         private:
69                 lua_State* m_L;
70                 LUABIND_TYPE_INFO m_info;
71         };
72
73 #else
74
75         typedef void(*error_callback_fun)(lua_State*);
76         typedef void(*cast_failed_callback_fun)(lua_State*, LUABIND_TYPE_INFO);
77
78         LUABIND_API void set_error_callback(error_callback_fun e);
79         LUABIND_API void set_cast_failed_callback(cast_failed_callback_fun c);
80         LUABIND_API error_callback_fun get_error_callback();
81         LUABIND_API cast_failed_callback_fun get_cast_failed_callback();
82
83 #endif
84
85         typedef int(*pcall_callback_fun)(lua_State*);
86         LUABIND_API void set_pcall_callback(pcall_callback_fun e);
87         LUABIND_API pcall_callback_fun get_pcall_callback();
88
89 }
90
91 #endif // LUABIND_ERROR_HPP_INCLUDED
92