style cleanup
This commit is contained in:
@@ -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;
|
||||||
@@ -127,9 +132,9 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
#define LUA_REGISTER_CLASS( T ) \
|
#define LUA_REGISTER_CLASS( T ) \
|
||||||
const char Luna##T<T>::s_className[] = #T; \
|
const char Luna##T<T>::s_className[] = #T; \
|
||||||
Luna##T<T>::RegTypeVector* Luna##T<T>::s_pvMethods = NULL; \
|
Luna##T<T>::RegTypeVector* Luna##T<T>::s_pvMethods = NULL; \
|
||||||
static Luna##T<T> registera; \
|
static Luna##T<T> registera; \
|
||||||
void T::PushSelf( lua_State *L ) { Luna##T<T>::Push( L, this ); }
|
void T::PushSelf( lua_State *L ) { Luna##T<T>::Push( L, this ); }
|
||||||
|
|
||||||
#define ADD_METHOD( method_name ) \
|
#define ADD_METHOD( method_name ) \
|
||||||
|
|||||||
Reference in New Issue
Block a user