From a7e7cf82276d96ebc7827ec09d06eaae4c5610d0 Mon Sep 17 00:00:00 2001 From: Pixel Date: Thu, 28 May 2009 19:57:04 -0700 Subject: Uniformizing the usage of luarecast. --- include/BLua.h | 39 +++++++++++++++++++-------------------- 1 file changed, 19 insertions(+), 20 deletions(-) (limited to 'include') 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 + 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(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 -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(b); - - if (!r) { - L->error(String("Object not compatible; expecting ") + typeid(r).name() + " but got *" + typeid(*b).name() + " instead."); - } - - return r; -} - - +template T * lua_recast(Lua * L, int n = 1) { return L->lua_recast(n); } /*******************************\ |** Let's have a sample of use **| -- cgit v1.2.3