aboutsummaryrefslogtreecommitdiff
path: root/src/FbTk/Luamm.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/FbTk/Luamm.cc')
-rw-r--r--src/FbTk/Luamm.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/FbTk/Luamm.cc b/src/FbTk/Luamm.cc
index 1ef751f..80d0926 100644
--- a/src/FbTk/Luamm.cc
+++ b/src/FbTk/Luamm.cc
@@ -24,6 +24,8 @@
24 24
25#include "Luamm.hh" 25#include "Luamm.hh"
26 26
27#include <sstream>
28
27namespace lua { 29namespace lua {
28 namespace { 30 namespace {
29 // keys for storing values in lua registry 31 // keys for storing values in lua registry
@@ -274,6 +276,35 @@ namespace lua {
274 throw lua::exception(this); 276 throw lua::exception(this);
275 } 277 }
276 278
279 void state::checkargno(int argno) throw(lua::check_error)
280 {
281 if(gettop() != argno) {
282 std::ostringstream str;
283 str << "Wrong number of arguments: expected " << argno << ", got " << gettop();
284 throw lua::check_error(str.str());
285 }
286 }
287
288 void *state::checkudata(int narg, const char *tname) throw(lua::check_error, std::bad_alloc)
289 {
290 checkstack(2);
291 stack_sentry s(*this);
292
293 void *p = touserdata(narg);
294 if(p != NULL) {
295 if(getmetatable(narg)) {
296 rawgetfield(REGISTRYINDEX, tname);
297 if(rawequal(-1, -2))
298 return p;
299 pop(2);
300 }
301 }
302 std::ostringstream str;
303 str << "Invalid argument #" << narg << ": expected " << type_name(TUSERDATA)
304 << ", got " << type_name(type(narg));
305 throw lua::check_error(str.str());
306 }
307
277 void state::checkstack(int extra) throw(std::bad_alloc) 308 void state::checkstack(int extra) throw(std::bad_alloc)
278 { 309 {
279 if(not lua_checkstack(cobj, extra)) 310 if(not lua_checkstack(cobj, extra))