aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk')
-rw-r--r--src/FbTk/Luamm.cc23
-rw-r--r--src/FbTk/Luamm.hh2
2 files changed, 21 insertions, 4 deletions
diff --git a/src/FbTk/Luamm.cc b/src/FbTk/Luamm.cc
index 80d0926..8824b06 100644
--- a/src/FbTk/Luamm.cc
+++ b/src/FbTk/Luamm.cc
@@ -285,6 +285,16 @@ namespace lua {
285 } 285 }
286 } 286 }
287 287
288 std::string state::checkstring(int narg) throw(lua::check_error, std::bad_alloc)
289 {
290 try {
291 return tostring(narg);
292 }
293 catch(lua::not_string_error &e) {
294 throw_check_error(narg, TSTRING);
295 }
296 }
297
288 void *state::checkudata(int narg, const char *tname) throw(lua::check_error, std::bad_alloc) 298 void *state::checkudata(int narg, const char *tname) throw(lua::check_error, std::bad_alloc)
289 { 299 {
290 checkstack(2); 300 checkstack(2);
@@ -299,10 +309,7 @@ namespace lua {
299 pop(2); 309 pop(2);
300 } 310 }
301 } 311 }
302 std::ostringstream str; 312 throw_check_error(narg, TUSERDATA);
303 str << "Invalid argument #" << narg << ": expected " << type_name(TUSERDATA)
304 << ", got " << type_name(type(narg));
305 throw lua::check_error(str.str());
306 } 313 }
307 314
308 void state::checkstack(int extra) throw(std::bad_alloc) 315 void state::checkstack(int extra) throw(std::bad_alloc)
@@ -478,6 +485,14 @@ namespace lua {
478 call(3, 0, 0); 485 call(3, 0, 0);
479 } 486 }
480 487
488 void state::throw_check_error(int narg, Type expected) throw(lua::check_error)
489 {
490 std::ostringstream str;
491 str << "Invalid argument #" << narg << ": expected " << type_name(expected)
492 << ", got " << type_name(type(narg));
493 throw lua::check_error(str.str());
494 }
495
481 std::string state::tostring(int index) throw(lua::not_string_error) 496 std::string state::tostring(int index) throw(lua::not_string_error)
482 { 497 {
483 size_t len; 498 size_t len;
diff --git a/src/FbTk/Luamm.hh b/src/FbTk/Luamm.hh
index b75fb12..01fb8b1 100644
--- a/src/FbTk/Luamm.hh
+++ b/src/FbTk/Luamm.hh
@@ -161,6 +161,7 @@ namespace lua {
161 161
162 bool safe_compare(lua_CFunction trampoline, int index1, int index2); 162 bool safe_compare(lua_CFunction trampoline, int index1, int index2);
163 void do_pushclosure(int n); 163 void do_pushclosure(int n);
164 void throw_check_error(int narg, Type expected) throw(lua::check_error) __attribute__((noreturn));
164 165
165 /** 166 /**
166 * The pointed-to value is true if this object still exists. We need this because the 167 * The pointed-to value is true if this object still exists. We need this because the
@@ -273,6 +274,7 @@ namespace lua {
273 // call() is a protected mode call, we don't allow unprotected calls 274 // call() is a protected mode call, we don't allow unprotected calls
274 void call(int nargs, int nresults, int errfunc = 0); 275 void call(int nargs, int nresults, int errfunc = 0);
275 void checkargno(int argno) throw(lua::check_error); 276 void checkargno(int argno) throw(lua::check_error);
277 std::string checkstring(int narg) throw(lua::check_error, std::bad_alloc);
276 void *checkudata(int narg, const char *tname) throw(lua::check_error, std::bad_alloc); 278 void *checkudata(int narg, const char *tname) throw(lua::check_error, std::bad_alloc);
277 template<typename T> 279 template<typename T>
278 T *checkudata(int narg, const char *tname) throw(lua::check_error, std::bad_alloc) { return static_cast<T *>(checkudata(narg, tname)); } 280 T *checkudata(int narg, const char *tname) throw(lua::check_error, std::bad_alloc) { return static_cast<T *>(checkudata(narg, tname)); }