コード例 #1
0
ファイル: tolua_map.c プロジェクト: FSource/FEngine
/* Register a usertype
	* It creates the correspoding metatable in the registry, for both 'type' and 'const type'.
	* It maps 'const type' as being also a 'type'
*/
TOLUA_API void tolua_usertype (lua_State* L, const char* type)
{
 char ctype[128] = "const ";
 strncat(ctype,type,120);

	/* create both metatables */
 if (tolua_newmetatable(L,ctype) && tolua_newmetatable(L,type))
	 mapsuper(L,type,ctype);             /* 'type' is also a 'const type' */
}
コード例 #2
0
TOLUA_API void tolua_open (lua_State* L)
{
 int top = lua_gettop(L);
 lua_pushstring(L,"tolua_opened");
 lua_rawget(L,LUA_REGISTRYINDEX);
 if (!lua_isboolean(L,-1))
 {
  lua_pushstring(L,"tolua_opened"); lua_pushboolean(L,1); 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);
		/* weak value table */
  lua_pushstring(L,"tolua_ubox"); lua_newtable(L); lua_pushvalue(L,-1);
		lua_pushliteral(L, "__mode"); lua_pushliteral(L, "v"); lua_rawset(L, -3);
		lua_setmetatable(L, -2); lua_rawset(L,LUA_REGISTRYINDEX);

		/* weak key table */
  lua_pushstring(L,"tolua_peer"); lua_newtable(L); lua_pushvalue(L,-1);
		lua_pushliteral(L, "__mode"); lua_pushliteral(L, "k"); lua_rawset(L, -3);
		lua_setmetatable(L, -2); lua_rawset(L,LUA_REGISTRYINDEX);

  tolua_newmetatable(L,"tolua_commonclass");

  tolua_module(L,NULL,0);
  tolua_beginmodule(L,NULL);
  tolua_module(L,"tolua",0);
  tolua_beginmodule(L,"tolua");
  tolua_function(L,"type",tolua_bnd_type);
  tolua_function(L,"takeownership",tolua_bnd_takeownership);
  tolua_function(L,"releaseownership",tolua_bnd_releaseownership);
  tolua_function(L,"cast",tolua_bnd_cast);
  tolua_endmodule(L);
  tolua_endmodule(L);    
 }
 lua_settop(L,top);
}
コード例 #3
0
ファイル: tolua_map.c プロジェクト: FSource/FEngine
TOLUA_API void tolua_open (lua_State* L)
{
 int top = lua_gettop(L);
 lua_pushstring(L,"tolua_opened");
 lua_rawget(L,LUA_REGISTRYINDEX);
 if (!lua_isboolean(L,-1))
 {
  lua_pushstring(L,"tolua_opened"); lua_pushboolean(L,1); lua_rawset(L,LUA_REGISTRYINDEX);

  #ifndef LUA_VERSION_NUM /* only prior to lua 5.1 */
  /* create peer object table */
  lua_pushstring(L, "tolua_peers"); lua_newtable(L);
  /* 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_setmetatable(L, -2);   /* stack: string peers */
  lua_rawset(L,LUA_REGISTRYINDEX);
  #endif

  /* create object ptr -> udata mapping table */
  lua_pushstring(L,"tolua_ubox"); lua_newtable(L);
  /* make weak value metatable for ubox table to allow userdata to be
     garbage-collected */
  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_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 */
  lua_pushstring(L, "tolua_gc_event");
  lua_pushstring(L, "tolua_gc");
  lua_rawget(L, LUA_REGISTRYINDEX);
  lua_pushstring(L, "tolua_super");
  lua_rawget(L, LUA_REGISTRYINDEX);
  lua_pushcclosure(L, class_gc_event, 2);
  lua_rawset(L, LUA_REGISTRYINDEX);

  tolua_newmetatable(L,"tolua_commonclass");

  tolua_module(L,NULL,0);
  tolua_beginmodule(L,NULL);
  tolua_module(L,"tolua",0);
  tolua_beginmodule(L,"tolua");
  tolua_function(L,"type",tolua_bnd_type);
  tolua_function(L,"takeownership",tolua_bnd_takeownership);
  tolua_function(L,"releaseownership",tolua_bnd_releaseownership);
  tolua_function(L,"cast",tolua_bnd_cast);
  tolua_function(L,"inherit", tolua_bnd_inherit);
  #ifdef LUA_VERSION_NUM /* lua 5.1 */
  tolua_function(L, "setpeer", tolua_bnd_setpeer);
  tolua_function(L, "getpeer", tolua_bnd_getpeer);
  #endif

  tolua_endmodule(L);
  tolua_endmodule(L);
 }
 lua_settop(L,top);
}