* update tolua++ source files

This commit is contained in:
YuLei Liao 2012-02-01 16:55:28 +08:00
parent e8e4de7077
commit 871e2b3b9c
6 changed files with 1511 additions and 1482 deletions

View File

@ -20,7 +20,7 @@
#define TOLUA_API extern #define TOLUA_API extern
#endif #endif
#define TOLUA_VERSION "tolua++-1.0.92" #define TOLUA_VERSION "tolua++-1.0.93"
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -33,7 +33,7 @@ extern "C" {
#define tolua_pushfieldcppstring(L,lo,idx,s) tolua_pushfieldstring(L, lo, idx, s.c_str()) #define tolua_pushfieldcppstring(L,lo,idx,s) tolua_pushfieldstring(L, lo, idx, s.c_str())
#ifndef TEMPLATE_BIND #ifndef TEMPLATE_BIND
#define TEMPLATE_BIND(p) #define TEMPLATE_BIND(p)
#endif #endif
#define TOLUA_TEMPLATE_BIND(p) #define TOLUA_TEMPLATE_BIND(p)
@ -69,19 +69,19 @@ TOLUA_API int tolua_isusertable (lua_State* L, int lo, const char* type, int def
TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err); TOLUA_API int tolua_isuserdata (lua_State* L, int lo, int def, tolua_Error* err);
TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def, tolua_Error* err); TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def, tolua_Error* err);
TOLUA_API int tolua_isvaluearray TOLUA_API int tolua_isvaluearray
(lua_State* L, int lo, int dim, int def, tolua_Error* err); (lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isbooleanarray TOLUA_API int tolua_isbooleanarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err); (lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isnumberarray TOLUA_API int tolua_isnumberarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err); (lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isstringarray TOLUA_API int tolua_isstringarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err); (lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_istablearray TOLUA_API int tolua_istablearray
(lua_State* L, int lo, int dim, int def, tolua_Error* err); (lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isuserdataarray TOLUA_API int tolua_isuserdataarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err); (lua_State* L, int lo, int dim, int def, tolua_Error* err);
TOLUA_API int tolua_isusertypearray TOLUA_API int tolua_isusertypearray
(lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err); (lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err);
TOLUA_API void tolua_open (lua_State* L); TOLUA_API void tolua_open (lua_State* L);
@ -101,7 +101,7 @@ TOLUA_API void tolua_variable (lua_State* L, const char* name, lua_CFunction get
TOLUA_API void tolua_array (lua_State* L,const char* name, lua_CFunction get, lua_CFunction set); TOLUA_API void tolua_array (lua_State* L,const char* name, lua_CFunction get, lua_CFunction set);
/* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type); */ /* TOLUA_API void tolua_set_call_event(lua_State* L, lua_CFunction func, char* type); */
TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base); TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base);
TOLUA_API void tolua_pushvalue (lua_State* L, int lo); TOLUA_API void tolua_pushvalue (lua_State* L, int lo);
TOLUA_API void tolua_pushboolean (lua_State* L, int value); TOLUA_API void tolua_pushboolean (lua_State* L, int value);

View File

@ -22,7 +22,7 @@
*/ */
static void storeatubox (lua_State* L, int lo) static void storeatubox (lua_State* L, int lo)
{ {
#ifdef LUA_VERSION_NUM #ifdef LUA_VERSION_NUM
lua_getfenv(L, lo); lua_getfenv(L, lo);
if (lua_rawequal(L, -1, TOLUA_NOPEER)) { if (lua_rawequal(L, -1, TOLUA_NOPEER)) {
lua_pop(L, 1); lua_pop(L, 1);
@ -33,7 +33,7 @@ static void storeatubox (lua_State* L, int lo)
lua_insert(L, -3); lua_insert(L, -3);
lua_settable(L, -3); /* on lua 5.1, we trade the "tolua_peers" lookup for a settable call */ lua_settable(L, -3); /* on lua 5.1, we trade the "tolua_peers" lookup for a settable call */
lua_pop(L, 1); lua_pop(L, 1);
#else #else
/* stack: key value (to be stored) */ /* stack: key value (to be stored) */
lua_pushstring(L,"tolua_peers"); lua_pushstring(L,"tolua_peers");
lua_rawget(L,LUA_REGISTRYINDEX); /* stack: k v ubox */ lua_rawget(L,LUA_REGISTRYINDEX); /* stack: k v ubox */
@ -51,7 +51,7 @@ static void storeatubox (lua_State* L, int lo)
lua_pop(L,1); /* pop ubox */ lua_pop(L,1); /* pop ubox */
lua_rawset(L,-3); /* store at table */ lua_rawset(L,-3); /* store at table */
lua_pop(L,1); /* pop ubox[u] */ lua_pop(L,1); /* pop ubox[u] */
#endif #endif
} }
/* Module index function /* Module index function
@ -140,7 +140,7 @@ static int class_index_event (lua_State* L)
if (t == LUA_TUSERDATA) if (t == LUA_TUSERDATA)
{ {
/* Access alternative table */ /* Access alternative table */
#ifdef LUA_VERSION_NUM /* new macro on version 5.1 */ #ifdef LUA_VERSION_NUM /* new macro on version 5.1 */
lua_getfenv(L,1); lua_getfenv(L,1);
if (!lua_rawequal(L, -1, TOLUA_NOPEER)) { if (!lua_rawequal(L, -1, TOLUA_NOPEER)) {
lua_pushvalue(L, 2); /* key */ lua_pushvalue(L, 2); /* key */
@ -148,7 +148,7 @@ static int class_index_event (lua_State* L)
if (!lua_isnil(L, -1)) if (!lua_isnil(L, -1))
return 1; return 1;
}; };
#else #else
lua_pushstring(L,"tolua_peers"); lua_pushstring(L,"tolua_peers");
lua_rawget(L,LUA_REGISTRYINDEX); /* stack: obj key ubox */ lua_rawget(L,LUA_REGISTRYINDEX); /* stack: obj key ubox */
lua_pushvalue(L,1); lua_pushvalue(L,1);
@ -160,7 +160,7 @@ static int class_index_event (lua_State* L)
if (!lua_isnil(L,-1)) if (!lua_isnil(L,-1))
return 1; return 1;
} }
#endif #endif
lua_settop(L,2); /* stack: obj key */ lua_settop(L,2); /* stack: obj key */
/* Try metatables */ /* Try metatables */
lua_pushvalue(L,1); /* stack: obj key obj */ lua_pushvalue(L,1); /* stack: obj key obj */

View File

@ -322,7 +322,7 @@ TOLUA_API int tolua_isusertype (lua_State* L, int lo, const char* type, int def,
} }
TOLUA_API int tolua_isvaluearray TOLUA_API int tolua_isvaluearray
(lua_State* L, int lo, int dim, int def, tolua_Error* err) (lua_State* L, int lo, int dim, int def, tolua_Error* err)
{ {
if (!tolua_istable(L,lo,def,err)) if (!tolua_istable(L,lo,def,err))
return 0; return 0;
@ -331,7 +331,7 @@ TOLUA_API int tolua_isvaluearray
} }
TOLUA_API int tolua_isbooleanarray TOLUA_API int tolua_isbooleanarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err) (lua_State* L, int lo, int dim, int def, tolua_Error* err)
{ {
if (!tolua_istable(L,lo,def,err)) if (!tolua_istable(L,lo,def,err))
return 0; return 0;
@ -358,7 +358,7 @@ TOLUA_API int tolua_isbooleanarray
} }
TOLUA_API int tolua_isnumberarray TOLUA_API int tolua_isnumberarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err) (lua_State* L, int lo, int dim, int def, tolua_Error* err)
{ {
if (!tolua_istable(L,lo,def,err)) if (!tolua_istable(L,lo,def,err))
return 0; return 0;
@ -385,7 +385,7 @@ TOLUA_API int tolua_isnumberarray
} }
TOLUA_API int tolua_isstringarray TOLUA_API int tolua_isstringarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err) (lua_State* L, int lo, int dim, int def, tolua_Error* err)
{ {
if (!tolua_istable(L,lo,def,err)) if (!tolua_istable(L,lo,def,err))
return 0; return 0;
@ -412,7 +412,7 @@ TOLUA_API int tolua_isstringarray
} }
TOLUA_API int tolua_istablearray TOLUA_API int tolua_istablearray
(lua_State* L, int lo, int dim, int def, tolua_Error* err) (lua_State* L, int lo, int dim, int def, tolua_Error* err)
{ {
if (!tolua_istable(L,lo,def,err)) if (!tolua_istable(L,lo,def,err))
return 0; return 0;
@ -439,7 +439,7 @@ TOLUA_API int tolua_istablearray
} }
TOLUA_API int tolua_isuserdataarray TOLUA_API int tolua_isuserdataarray
(lua_State* L, int lo, int dim, int def, tolua_Error* err) (lua_State* L, int lo, int dim, int def, tolua_Error* err)
{ {
if (!tolua_istable(L,lo,def,err)) if (!tolua_istable(L,lo,def,err))
return 0; return 0;
@ -466,7 +466,7 @@ TOLUA_API int tolua_isuserdataarray
} }
TOLUA_API int tolua_isusertypearray TOLUA_API int tolua_isusertypearray
(lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err) (lua_State* L, int lo, const char* type, int dim, int def, tolua_Error* err)
{ {
if (!tolua_istable(L,lo,def,err)) if (!tolua_istable(L,lo,def,err))
return 0; return 0;
@ -494,7 +494,7 @@ TOLUA_API int tolua_isusertypearray
#if 0 #if 0
int tolua_isbooleanfield int tolua_isbooleanfield
(lua_State* L, int lo, int i, int def, tolua_Error* err) (lua_State* L, int lo, int i, int def, tolua_Error* err)
{ {
lua_pushnumber(L,i); lua_pushnumber(L,i);
lua_gettable(L,lo); lua_gettable(L,lo);
@ -512,7 +512,7 @@ int tolua_isbooleanfield
} }
int tolua_isnumberfield int tolua_isnumberfield
(lua_State* L, int lo, int i, int def, tolua_Error* err) (lua_State* L, int lo, int i, int def, tolua_Error* err)
{ {
lua_pushnumber(L,i); lua_pushnumber(L,i);
lua_gettable(L,lo); lua_gettable(L,lo);
@ -530,7 +530,7 @@ int tolua_isnumberfield
} }
int tolua_isstringfield int tolua_isstringfield
(lua_State* L, int lo, int i, int def, tolua_Error* err) (lua_State* L, int lo, int i, int def, tolua_Error* err)
{ {
lua_pushnumber(L,i); lua_pushnumber(L,i);
lua_gettable(L,lo); lua_gettable(L,lo);
@ -548,7 +548,7 @@ int tolua_isstringfield
} }
int tolua_istablefield int tolua_istablefield
(lua_State* L, int lo, int i, int def, tolua_Error* err) (lua_State* L, int lo, int i, int def, tolua_Error* err)
{ {
lua_pushnumber(L,i+1); lua_pushnumber(L,i+1);
lua_gettable(L,lo); lua_gettable(L,lo);
@ -565,7 +565,7 @@ int tolua_istablefield
} }
int tolua_isusertablefield int tolua_isusertablefield
(lua_State* L, int lo, const char* type, int i, int def, tolua_Error* err) (lua_State* L, int lo, const char* type, int i, int def, tolua_Error* err)
{ {
lua_pushnumber(L,i); lua_pushnumber(L,i);
lua_gettable(L,lo); lua_gettable(L,lo);
@ -583,7 +583,7 @@ int tolua_isusertablefield
} }
int tolua_isuserdatafield int tolua_isuserdatafield
(lua_State* L, int lo, int i, int def, tolua_Error* err) (lua_State* L, int lo, int i, int def, tolua_Error* err)
{ {
lua_pushnumber(L,i); lua_pushnumber(L,i);
lua_gettable(L,lo); lua_gettable(L,lo);
@ -601,7 +601,7 @@ int tolua_isuserdatafield
} }
int tolua_isusertypefield int tolua_isusertypefield
(lua_State* L, int lo, const char* type, int i, int def, tolua_Error* err) (lua_State* L, int lo, const char* type, int i, int def, tolua_Error* err)
{ {
lua_pushnumber(L,i); lua_pushnumber(L,i);
lua_gettable(L,lo); lua_gettable(L,lo);

View File

@ -25,17 +25,17 @@
/* Create metatable /* Create metatable
* Create and register new metatable * Create and register new metatable
*/ */
static int tolua_newmetatable (lua_State* L, char* name) static int tolua_newmetatable (lua_State* L, const char* name)
{ {
int r = luaL_newmetatable(L,name); int r = luaL_newmetatable(L,name);
#ifdef LUA_VERSION_NUM /* only lua 5.1 */ #ifdef LUA_VERSION_NUM /* only lua 5.1 */
if (r) { if (r) {
lua_pushvalue(L, -1); lua_pushvalue(L, -1);
lua_pushstring(L, name); lua_pushstring(L, name);
lua_settable(L, LUA_REGISTRYINDEX); /* reg[mt] = type_name */ lua_settable(L, LUA_REGISTRYINDEX); /* reg[mt] = type_name */
}; };
#endif #endif
if (r) if (r)
tolua_classevents(L); /* set meta events */ tolua_classevents(L); /* set meta events */
@ -107,10 +107,14 @@ static void set_ubox(lua_State* L) {
} else { } else {
/* mt basemt nil */ /* mt basemt nil */
lua_pop(L, 1); lua_pop(L, 1);
lua_pushstring(L,"tolua_ubox"); lua_newtable(L); lua_pushstring(L,"tolua_ubox");
lua_newtable(L);
/* make weak value metatable for ubox table to allow userdata to be /* make weak value metatable for ubox table to allow userdata to be
garbage-collected */ garbage-collected */
lua_newtable(L); lua_pushliteral(L, "__mode"); lua_pushliteral(L, "v"); lua_rawset(L, -3); /* stack: string ubox mt */ lua_newtable(L);
lua_pushliteral(L, "__mode");
lua_pushliteral(L, "v");
lua_rawset(L, -3); /* stack: string ubox mt */
lua_setmetatable(L, -2); /* stack:mt basemt string ubox */ lua_setmetatable(L, -2); /* stack:mt basemt string ubox */
lua_rawset(L,-4); lua_rawset(L,-4);
}; };
@ -161,11 +165,11 @@ static int tolua_bnd_takeownership (lua_State* L)
{ {
lua_pop(L,1); /* clear metatable off stack */ lua_pop(L,1); /* clear metatable off stack */
/* force garbage collection to avoid C to reuse a to-be-collected address */ /* force garbage collection to avoid C to reuse a to-be-collected address */
#ifdef LUA_VERSION_NUM #ifdef LUA_VERSION_NUM
lua_gc(L, LUA_GCCOLLECT, 0); lua_gc(L, LUA_GCCOLLECT, 0);
#else #else
lua_setgcthreshold(L,0); lua_setgcthreshold(L,0);
#endif #endif
success = tolua_register_gc(L,1); success = tolua_register_gc(L,1);
} }
@ -183,11 +187,11 @@ static int tolua_bnd_releaseownership (lua_State* L)
{ {
void* u = *((void**)lua_touserdata(L,1)); void* u = *((void**)lua_touserdata(L,1));
/* force garbage collection to avoid releasing a to-be-collected address */ /* force garbage collection to avoid releasing a to-be-collected address */
#ifdef LUA_VERSION_NUM #ifdef LUA_VERSION_NUM
lua_gc(L, LUA_GCCOLLECT, 0); lua_gc(L, LUA_GCCOLLECT, 0);
#else #else
lua_setgcthreshold(L,0); lua_setgcthreshold(L,0);
#endif #endif
lua_pushstring(L,"tolua_gc"); lua_pushstring(L,"tolua_gc");
lua_rawget(L,LUA_REGISTRYINDEX); lua_rawget(L,LUA_REGISTRYINDEX);
lua_pushlightuserdata(L,u); lua_pushlightuserdata(L,u);
@ -210,7 +214,7 @@ static int tolua_bnd_releaseownership (lua_State* L)
static int tolua_bnd_cast (lua_State* L) static int tolua_bnd_cast (lua_State* L)
{ {
/* // old code /* // old code
void* v = tolua_tousertype(L,1,NULL); void* v = tolua_tousertype(L,1,NULL);
const char* s = tolua_tostring(L,2,NULL); const char* s = tolua_tostring(L,2,NULL);
if (v && s) if (v && s)
@ -218,7 +222,7 @@ static int tolua_bnd_cast (lua_State* L)
else else
lua_pushnil(L); lua_pushnil(L);
return 1; return 1;
*/ */
void* v; void* v;
const char* s; const char* s;
@ -289,27 +293,46 @@ TOLUA_API void tolua_open (lua_State* L)
lua_rawget(L,LUA_REGISTRYINDEX); lua_rawget(L,LUA_REGISTRYINDEX);
if (!lua_isboolean(L,-1)) if (!lua_isboolean(L,-1))
{ {
lua_pushstring(L,"tolua_opened"); lua_pushboolean(L,1); lua_rawset(L,LUA_REGISTRYINDEX); lua_pushstring(L,"tolua_opened");
lua_pushboolean(L,1);
lua_rawset(L,LUA_REGISTRYINDEX);
#ifndef LUA_VERSION_NUM /* only prior to lua 5.1 */ #ifndef LUA_VERSION_NUM /* only prior to lua 5.1 */
/* create peer object table */ /* create peer object table */
lua_pushstring(L, "tolua_peers"); lua_newtable(L); lua_pushstring(L, "tolua_peers");
lua_newtable(L);
/* make weak key metatable for peers indexed by userdata object */ /* make weak key metatable for peers indexed by userdata object */
lua_newtable(L); lua_pushliteral(L, "__mode"); lua_pushliteral(L, "k"); lua_rawset(L, -3); /* stack: string peers mt */ lua_newtable(L);
lua_pushliteral(L, "__mode");
lua_pushliteral(L, "k");
lua_rawset(L, -3); /* stack: string peers mt */
lua_setmetatable(L, -2); /* stack: string peers */ lua_setmetatable(L, -2); /* stack: string peers */
lua_rawset(L,LUA_REGISTRYINDEX); lua_rawset(L,LUA_REGISTRYINDEX);
#endif #endif
/* create object ptr -> udata mapping table */ /* create object ptr -> udata mapping table */
lua_pushstring(L,"tolua_ubox"); lua_newtable(L); lua_pushstring(L,"tolua_ubox");
lua_newtable(L);
/* make weak value metatable for ubox table to allow userdata to be /* make weak value metatable for ubox table to allow userdata to be
garbage-collected */ garbage-collected */
lua_newtable(L); lua_pushliteral(L, "__mode"); lua_pushliteral(L, "v"); lua_rawset(L, -3); /* stack: string ubox mt */ lua_newtable(L);
lua_pushliteral(L, "__mode");
lua_pushliteral(L, "v");
lua_rawset(L, -3); /* stack: string ubox mt */
lua_setmetatable(L, -2); /* stack: string ubox */ lua_setmetatable(L, -2); /* stack: string ubox */
lua_rawset(L,LUA_REGISTRYINDEX); lua_rawset(L,LUA_REGISTRYINDEX);
lua_pushstring(L,"tolua_super"); lua_newtable(L); lua_rawset(L,LUA_REGISTRYINDEX); // /* create object ptr -> class type mapping table */
lua_pushstring(L,"tolua_gc"); lua_newtable(L);lua_rawset(L,LUA_REGISTRYINDEX); // lua_pushstring(L, "tolua_ptr2type");
// lua_newtable(L);
// lua_rawset(L, LUA_REGISTRYINDEX);
lua_pushstring(L,"tolua_super");
lua_newtable(L);
lua_rawset(L,LUA_REGISTRYINDEX);
lua_pushstring(L,"tolua_gc");
lua_newtable(L);
lua_rawset(L,LUA_REGISTRYINDEX);
/* create gc_event closure */ /* create gc_event closure */
lua_pushstring(L, "tolua_gc_event"); lua_pushstring(L, "tolua_gc_event");
@ -331,10 +354,10 @@ TOLUA_API void tolua_open (lua_State* L)
tolua_function(L,"releaseownership",tolua_bnd_releaseownership); tolua_function(L,"releaseownership",tolua_bnd_releaseownership);
tolua_function(L,"cast",tolua_bnd_cast); tolua_function(L,"cast",tolua_bnd_cast);
tolua_function(L,"inherit", tolua_bnd_inherit); tolua_function(L,"inherit", tolua_bnd_inherit);
#ifdef LUA_VERSION_NUM /* lua 5.1 */ #ifdef LUA_VERSION_NUM /* lua 5.1 */
tolua_function(L, "setpeer", tolua_bnd_setpeer); tolua_function(L, "setpeer", tolua_bnd_setpeer);
tolua_function(L, "getpeer", tolua_bnd_getpeer); tolua_function(L, "getpeer", tolua_bnd_getpeer);
#endif #endif
tolua_endmodule(L); tolua_endmodule(L);
tolua_endmodule(L); tolua_endmodule(L);
@ -696,10 +719,10 @@ TOLUA_API void tolua_array (lua_State* L, const char* name, lua_CFunction get, l
TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size, const char* name) { TOLUA_API void tolua_dobuffer(lua_State* L, char* B, unsigned int size, const char* name) {
#ifdef LUA_VERSION_NUM /* lua 5.1 */ #ifdef LUA_VERSION_NUM /* lua 5.1 */
luaL_loadbuffer(L, B, size, name) || lua_pcall(L, 0, 0, 0); luaL_loadbuffer(L, B, size, name) || lua_pcall(L, 0, 0, 0);
#else #else
lua_dobuffer(L, B, size, name); lua_dobuffer(L, B, size, name);
#endif #endif
}; };

View File

@ -54,7 +54,11 @@ TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type)
lua_pushnil(L); lua_pushnil(L);
else else
{ {
luaL_getmetatable(L, type); luaL_getmetatable(L, type); /* stack: mt */
if (lua_isnil(L, -1)) { /* NOT FOUND metatable */
lua_pop(L, 1);
return;
}
lua_pushstring(L,"tolua_ubox"); lua_pushstring(L,"tolua_ubox");
lua_rawget(L,-2); /* stack: mt ubox */ lua_rawget(L,-2); /* stack: mt ubox */
if (lua_isnil(L, -1)) { if (lua_isnil(L, -1)) {
@ -62,25 +66,27 @@ TOLUA_API void tolua_pushusertype (lua_State* L, void* value, const char* type)
lua_pushstring(L, "tolua_ubox"); lua_pushstring(L, "tolua_ubox");
lua_rawget(L, LUA_REGISTRYINDEX); lua_rawget(L, LUA_REGISTRYINDEX);
}; };
lua_pushlightuserdata(L,value);
lua_rawget(L,-2); /* stack: mt ubox ubox[u] */ lua_pushlightuserdata(L,value); /* stack: mt ubox key<value> */
lua_rawget(L,-2); /* stack: mt ubox ubox[value] */
if (lua_isnil(L,-1)) if (lua_isnil(L,-1))
{ {
lua_pop(L,1); /* stack: mt ubox */ lua_pop(L,1); /* stack: mt ubox */
lua_pushlightuserdata(L,value); lua_pushlightuserdata(L,value);
*(void**)lua_newuserdata(L,sizeof(void *)) = value; /* stack: mt ubox u newud */ *(void**)lua_newuserdata(L,sizeof(void *)) = value; /* stack: mt ubox value newud */
lua_pushvalue(L,-1); /* stack: mt ubox u newud newud */ lua_pushvalue(L,-1); /* stack: mt ubox value newud newud */
lua_insert(L,-4); /* stack: mt newud ubox u newud */ lua_insert(L,-4); /* stack: mt newud ubox value newud */
lua_rawset(L,-3); /* stack: mt newud ubox */ lua_rawset(L,-3); /* ubox[value] = newud, stack: mt newud ubox */
lua_pop(L,1); /* stack: mt newud */ lua_pop(L,1); /* stack: mt newud */
/*luaL_getmetatable(L,type);*/ /*luaL_getmetatable(L,type);*/
lua_pushvalue(L, -2); /* stack: mt newud mt */ lua_pushvalue(L, -2); /* stack: mt newud mt */
lua_setmetatable(L,-2); /* stack: mt newud */ lua_setmetatable(L,-2); /* update mt, stack: mt newud */
#ifdef LUA_VERSION_NUM #ifdef LUA_VERSION_NUM
lua_pushvalue(L, TOLUA_NOPEER); lua_pushvalue(L, TOLUA_NOPEER);
lua_setfenv(L, -2); lua_setfenv(L, -2);
#endif #endif
} }
else else
{ {