cleanup; remove userdataType
This commit is contained in:
@@ -20,8 +20,6 @@ protected:
|
|||||||
int (*mfunc)(T *p, lua_State *L);
|
int (*mfunc)(T *p, lua_State *L);
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef struct { T *pT; } userdataType;
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
static void Register( Lua *L )
|
static void Register( Lua *L )
|
||||||
{
|
{
|
||||||
@@ -103,15 +101,15 @@ public:
|
|||||||
LuaHelpers::TypeError( L, narg, m_sClassName );
|
LuaHelpers::TypeError( L, narg, m_sClassName );
|
||||||
}
|
}
|
||||||
|
|
||||||
userdataType *pUserdata = (userdataType *) lua_touserdata( L, narg );
|
void **pData = (void **) lua_touserdata( L, narg );
|
||||||
return pUserdata->pT; // pointer to T object
|
return (T *) *pData;
|
||||||
}
|
}
|
||||||
|
|
||||||
// push a userdata containing a pointer to T object
|
// push a userdata containing a pointer to T object
|
||||||
static int Push( Lua *L, T* p )
|
static int Push( Lua *L, T* p )
|
||||||
{
|
{
|
||||||
userdataType *ud = static_cast<userdataType*>( lua_newuserdata(L, sizeof(userdataType)) );
|
void **pData = (void **) lua_newuserdata( L, sizeof(void *) );
|
||||||
ud->pT = p; // store pointer to object in userdata
|
*pData = p; // store pointer to object in userdata
|
||||||
luaL_getmetatable( L, m_sClassName ); // lookup metatable in Lua registry
|
luaL_getmetatable( L, m_sClassName ); // lookup metatable in Lua registry
|
||||||
lua_setmetatable( L, -2 );
|
lua_setmetatable( L, -2 );
|
||||||
return 1; // userdata containing pointer to T object
|
return 1; // userdata containing pointer to T object
|
||||||
@@ -142,9 +140,9 @@ private:
|
|||||||
/* Two objects are equal if the underlying object is the same. */
|
/* Two objects are equal if the underlying object is the same. */
|
||||||
static int equal( lua_State *L )
|
static int equal( lua_State *L )
|
||||||
{
|
{
|
||||||
userdataType *obj1 = (userdataType *) lua_touserdata( L, 1 );
|
void **obj1 = (void **) lua_touserdata( L, 1 );
|
||||||
userdataType *obj2 = (userdataType *) lua_touserdata( L, 2 );
|
void **obj2 = (void **) lua_touserdata( L, 2 );
|
||||||
lua_pushboolean( L, obj1->pT == obj2->pT );
|
lua_pushboolean( L, *obj1 == *obj2 );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -157,8 +155,8 @@ private:
|
|||||||
static int tostring_T( lua_State *L )
|
static int tostring_T( lua_State *L )
|
||||||
{
|
{
|
||||||
char buff[32];
|
char buff[32];
|
||||||
userdataType *ud = static_cast<userdataType*>( lua_touserdata(L, 1) );
|
void **pData = (void **) lua_touserdata( L, 1 );
|
||||||
T *obj = ud->pT;
|
T *obj = (T *) *pData;
|
||||||
sprintf( buff, "%p", obj) ;
|
sprintf( buff, "%p", obj) ;
|
||||||
lua_pushfstring( L, "%s (%s)", m_sClassName, buff );
|
lua_pushfstring( L, "%s (%s)", m_sClassName, buff );
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user