diff options
-rw-r--r-- | src/FbTk/Luamm.cc | 15 | ||||
-rw-r--r-- | src/FbTk/Luamm.hh | 58 |
2 files changed, 25 insertions, 48 deletions
diff --git a/src/FbTk/Luamm.cc b/src/FbTk/Luamm.cc index 81a8fb3..d17096f 100644 --- a/src/FbTk/Luamm.cc +++ b/src/FbTk/Luamm.cc | |||
@@ -108,10 +108,6 @@ namespace lua { | |||
108 | /* | 108 | /* |
109 | * This function is called when lua encounters an error outside of any protected | 109 | * This function is called when lua encounters an error outside of any protected |
110 | * environment | 110 | * environment |
111 | * Throwing the exception through lua code appears to work, even if it was compiled | ||
112 | * without -fexceptions. If it turns out, it fails in some conditions, it could be | ||
113 | * replaced with some longjmp() magic. But that shouldn't be necessary, as this function | ||
114 | * will not be called under normal conditions (we execute everything in protected mode). | ||
115 | */ | 111 | */ |
116 | int panic_throw(lua_State *l) | 112 | int panic_throw(lua_State *l) |
117 | { | 113 | { |
@@ -191,6 +187,17 @@ namespace lua { | |||
191 | L->pop(1); | 187 | L->pop(1); |
192 | } | 188 | } |
193 | 189 | ||
190 | exception::exception(const exception &other) | ||
191 | : std::runtime_error(other), L(other.L) | ||
192 | { | ||
193 | L->checkstack(2); | ||
194 | |||
195 | L->rawgetfield(REGISTRYINDEX, lua_exception_namespace); | ||
196 | L->rawgeti(-1, other.key); | ||
197 | key = L->ref(-2); | ||
198 | L->pop(1); | ||
199 | } | ||
200 | |||
194 | exception::~exception() throw() | 201 | exception::~exception() throw() |
195 | { | 202 | { |
196 | if(not L) | 203 | if(not L) |
diff --git a/src/FbTk/Luamm.hh b/src/FbTk/Luamm.hh index 5c8d382..e173be9 100644 --- a/src/FbTk/Luamm.hh +++ b/src/FbTk/Luamm.hh | |||
@@ -26,8 +26,9 @@ | |||
26 | #include <memory> | 26 | #include <memory> |
27 | #include <stdexcept> | 27 | #include <stdexcept> |
28 | 28 | ||
29 | #include <lua.h> | ||
30 | #include <lauxlib.h> | 29 | #include <lauxlib.h> |
30 | #include <lua.h> | ||
31 | #include <lualib.h> | ||
31 | 32 | ||
32 | #include "Slot.hh" | 33 | #include "Slot.hh" |
33 | 34 | ||
@@ -81,79 +82,50 @@ namespace lua { | |||
81 | * pushed into the same state it was generated in. | 82 | * pushed into the same state it was generated in. |
82 | */ | 83 | */ |
83 | class exception: public std::runtime_error { | 84 | class exception: public std::runtime_error { |
84 | /* | ||
85 | * We only allow moving, to avoid complications with multiple references. It shouldn't be | ||
86 | * difficult to modify this to work with copying, if that proves unavoidable. | ||
87 | */ | ||
88 | state *L; | 85 | state *L; |
89 | int key; | 86 | int key; |
90 | 87 | ||
91 | static std::string get_error_msg(state *L); | 88 | static std::string get_error_msg(state *L); |
92 | 89 | ||
93 | exception(const exception &) = delete; | 90 | exception& operator=(const exception &other); // not implemented |
94 | const exception& operator=(const exception &) = delete; | ||
95 | |||
96 | public: | ||
97 | exception(exception &&other) | ||
98 | : std::runtime_error(std::move(other)), L(other.L), key(other.key) | ||
99 | { other.L = NULL; } | ||
100 | 91 | ||
92 | public: | ||
101 | explicit exception(state *l); | 93 | explicit exception(state *l); |
94 | exception(const exception &other); | ||
102 | virtual ~exception() throw(); | 95 | virtual ~exception() throw(); |
103 | 96 | ||
104 | void push_lua_error(state *l); | 97 | void push_lua_error(state *l); |
105 | }; | 98 | }; |
106 | 99 | ||
107 | class not_string_error: public std::runtime_error { | 100 | class not_string_error: public std::runtime_error { |
108 | public: | 101 | public: |
109 | not_string_error() | 102 | not_string_error() |
110 | : std::runtime_error("Cannot convert value to a string") | 103 | : std::runtime_error("Cannot convert value to a string") |
111 | {} | 104 | {} |
112 | }; | 105 | }; |
113 | 106 | ||
114 | // the name says it all | 107 | // the name says it all |
115 | class syntax_error: public lua::exception { | 108 | class syntax_error: public lua::exception { |
116 | syntax_error(const syntax_error &) = delete; | 109 | public: |
117 | const syntax_error& operator=(const syntax_error &) = delete; | ||
118 | |||
119 | public: | ||
120 | syntax_error(state *L) | 110 | syntax_error(state *L) |
121 | : lua::exception(L) | 111 | : lua::exception(L) |
122 | {} | 112 | {} |
123 | |||
124 | syntax_error(syntax_error &&other) | ||
125 | : lua::exception(std::move(other)) | ||
126 | {} | ||
127 | }; | 113 | }; |
128 | 114 | ||
129 | // loadfile() encountered an error while opening/reading the file | 115 | // loadfile() encountered an error while opening/reading the file |
130 | class file_error: public lua::exception { | 116 | class file_error: public lua::exception { |
131 | file_error(const file_error &) = delete; | 117 | public: |
132 | const file_error& operator=(const file_error &) = delete; | ||
133 | |||
134 | public: | ||
135 | file_error(state *L) | 118 | file_error(state *L) |
136 | : lua::exception(L) | 119 | : lua::exception(L) |
137 | {} | 120 | {} |
138 | |||
139 | file_error(file_error &&other) | ||
140 | : lua::exception(std::move(other)) | ||
141 | {} | ||
142 | }; | 121 | }; |
143 | 122 | ||
144 | // double fault, lua encountered an error while running the error handler function | 123 | // double fault, lua encountered an error while running the error handler function |
145 | class errfunc_error: public lua::exception { | 124 | class errfunc_error: public lua::exception { |
146 | errfunc_error(const errfunc_error &) = delete; | 125 | public: |
147 | const errfunc_error& operator=(const errfunc_error &) = delete; | ||
148 | |||
149 | public: | ||
150 | errfunc_error(state *L) | 126 | errfunc_error(state *L) |
151 | : lua::exception(L) | 127 | : lua::exception(L) |
152 | {} | 128 | {} |
153 | |||
154 | errfunc_error(errfunc_error &&other) | ||
155 | : lua::exception(std::move(other)) | ||
156 | {} | ||
157 | }; | 129 | }; |
158 | 130 | ||
159 | // a fancy wrapper around lua_State | 131 | // a fancy wrapper around lua_State |
@@ -313,13 +285,11 @@ namespace lua { | |||
313 | * since we have exception.what() for that, putting the message on the stack is not | 285 | * since we have exception.what() for that, putting the message on the stack is not |
314 | * necessary. | 286 | * necessary. |
315 | */ | 287 | */ |
316 | class stack_sentry { | 288 | class stack_sentry: private FbTk::NotCopyable { |
317 | state *L; | 289 | state *L; |
318 | int n; | 290 | int n; |
319 | 291 | ||
320 | stack_sentry(const stack_sentry &) = delete; | 292 | public: |
321 | const stack_sentry& operator=(const stack_sentry &) = delete; | ||
322 | public: | ||
323 | explicit stack_sentry(state &l, int n_ = 0) throw() | 293 | explicit stack_sentry(state &l, int n_ = 0) throw() |
324 | : L(&l), n(l.gettop()+n_) | 294 | : L(&l), n(l.gettop()+n_) |
325 | { assert(n >= 0); } | 295 | { assert(n >= 0); } |