style cleanup

This commit is contained in:
Chris Danford
2005-02-01 07:50:26 +00:00
parent d6c33c96d6
commit 275edd909b
+10 -5
View File
@@ -34,7 +34,8 @@ class Luna
typedef struct { T *pT; } userdataType; typedef struct { T *pT; } userdataType;
public: public:
static void Register(lua_State *L) { static void Register(lua_State *L)
{
lua_newtable(L); lua_newtable(L);
int methods = lua_gettop(L); int methods = lua_gettop(L);
@@ -73,7 +74,8 @@ public:
} }
// get userdata from Lua stack and return pointer to T object // get userdata from Lua stack and return pointer to T object
static T *check(lua_State *L, int narg) { static T *check(lua_State *L, int narg)
{
userdataType *ud = userdataType *ud =
static_cast<userdataType*>(luaL_checkudata(L, narg, s_className)); static_cast<userdataType*>(luaL_checkudata(L, narg, s_className));
if(!ud) luaL_typerror(L, narg, s_className); if(!ud) luaL_typerror(L, narg, s_className);
@@ -83,7 +85,8 @@ public:
private: private:
// member function dispatcher // member function dispatcher
static int thunk(lua_State *L) { static int thunk(lua_State *L)
{
// stack has userdata, followed by method args // stack has userdata, followed by method args
T *obj = check(L, 1); // get 'self', or if you prefer, 'this' T *obj = check(L, 1); // get 'self', or if you prefer, 'this'
lua_remove(L, 1); // remove self so member function args start at index 1 lua_remove(L, 1); // remove self so member function args start at index 1
@@ -95,7 +98,8 @@ private:
public: public:
// create a new T object and // create a new T object and
// push onto the Lua stack a userdata containing a pointer to T object // push onto the Lua stack a userdata containing a pointer to T object
static int Push(lua_State *L, T* p ) { static int Push(lua_State *L, T* p )
{
userdataType *ud = static_cast<userdataType*>(lua_newuserdata(L, sizeof(userdataType))); userdataType *ud = static_cast<userdataType*>(lua_newuserdata(L, sizeof(userdataType)));
ud->pT = p; // store pointer to object in userdata ud->pT = p; // store pointer to object in userdata
luaL_getmetatable(L, s_className); // lookup metatable in Lua registry luaL_getmetatable(L, s_className); // lookup metatable in Lua registry
@@ -115,7 +119,8 @@ public:
private: private:
static const char s_className[]; static const char s_className[];
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)); userdataType *ud = static_cast<userdataType*>(lua_touserdata(L, 1));
T *obj = ud->pT; T *obj = ud->pT;