aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Luamm.hh
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Luamm.hh')
-rw-r--r--src/FbTk/Luamm.hh58
1 files changed, 14 insertions, 44 deletions
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); }