summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/BLua.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/include/BLua.h b/include/BLua.h
index 2ca7b2a..fc8adb2 100644
--- a/include/BLua.h
+++ b/include/BLua.h
@@ -336,6 +336,26 @@ class LuaHelpers : public Base {
}
};
+template<class T>
+T * lua_recast(Lua * L, int n = 1) {
+ Base * b;
+ T * r;
+
+ b = (Base *) LuaObject::getme(L, n);
+ if (!b) {
+ L->error("Base object required; got null.");
+ }
+
+ r = dynamic_cast<T *>(b);
+
+ if (!r) {
+ L->error(String("Object not compatible; expecting ") + typeid(r).name() + " but got *" + typeid(*b).name() + " instead.");
+ }
+
+ return r;
+}
+
+
/*******************************\
|** Let's have a sample of use **|