My Project
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 #include <luabind/typeid.hpp>
30 
31 struct lua_State;
32 
33 namespace luabind
34 {
35 
36 #ifndef LUABIND_NO_EXCEPTIONS
37 
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
47  {
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()
52  {
53  return "lua runtime error";
54  }
55  private:
56  lua_State* m_L;
57  };
58 
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
63  {
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;
72  };
73 
74 #else
75 
76  typedef void(*error_callback_fun)(lua_State*);
77  typedef void(*cast_failed_callback_fun)(lua_State*, type_id const&);
78 
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();
83 
84 #endif
85 
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();
89 
90 }
91 
92 #endif // LUABIND_ERROR_HPP_INCLUDED
93 
Definition: typeid.hpp:22
Definition: minilua.c:461
Definition: PEtypes.h:507
Definition: error.hpp:46
Definition: error.hpp:62