diff options
Diffstat (limited to 'include/BLua.h')
-rw-r--r-- | include/BLua.h | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/include/BLua.h b/include/BLua.h index fc8adb2..fe0b33b 100644 --- a/include/BLua.h +++ b/include/BLua.h @@ -139,6 +139,24 @@ class Lua : public Base { void SetPrinter(LuaPrinter *); void puts(const char * msg); + template<class T> + T * recast(int n = 1) { + Base * b; + T * r; + + b = (Base *) LuaObject::getme(this, n); + if (!b) { + error("Base object required; got null."); + } + + r = dynamic_cast<T *>(b); + + if (!r) { + error(String("Object not compatible; expecting ") + typeid(r).name() + " but got *" + typeid(*b).name() + " instead."); + } + + return r; +} protected: virtual Lua * spawn_from_thread(lua_State *); Lua(lua_State *); @@ -336,26 +354,7 @@ 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; -} - - +template<class T> T * lua_recast(Lua * L, int n = 1) { return L->lua_recast(n); } /*******************************\ |** Let's have a sample of use **| |