Пример #1
0
/* Map C class
    * It maps a C class, setting the appropriate inheritance and super classes.
*/
TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col)
{
    // stack: module
    char cname[128] = "const ";
    char cbase[128] = "const ";
    strncat(cname,name,120);
    strncat(cbase,base,120);

    mapinheritance(L,name,base);
    mapinheritance(L,cname,name);

    mapsuper(L,cname,cbase);
    mapsuper(L,name,base);

    lua_pushstring(L,lname);        // stack: module lname

    push_collector(L, name, col);
    /*
    luaL_getmetatable(L,name);
    lua_pushstring(L,".collector");
    lua_pushcfunction(L,col);

    lua_rawset(L,-3);
    */

// ---- disable by SunLightJuly, 2014.6.5
    //luaL_getmetatable(L,name);
    //lua_rawset(L,-3);              /* assign class metatable to module */
// ---- disable end
//---- create a new class table, set it's metatable, and assign it to module
    lua_newtable(L);                    // stack: module lname table
    luaL_getmetatable(L,name);          // stack: module lname table mt
    lua_setmetatable(L, -2);            // stack: module lname table
    //Use a key named ".isclass" to be a flag of class_table
    lua_pushliteral(L, ".isclass");
    lua_pushboolean(L, 1);
    lua_rawset(L, -3);                  // stack: module lname table
    lua_rawset(L, -3);                  // stack: module
//---- by SunLightJuly, 2014.6.5

    /* now we also need to store the collector table for the const
       instances of the class */
    push_collector(L, cname, col);
    /*
    luaL_getmetatable(L,cname);
    lua_pushstring(L,".collector");
    lua_pushcfunction(L,col);
    lua_rawset(L,-3);
    lua_pop(L,1);
    */


}
Пример #2
0
/* Map C class
    * It maps a C class, setting the appropriate inheritance and super classes.
*/
TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col)
{
    char cname[128] = "const ";
    char cbase[128] = "const ";
    strncat(cname,name,120);
    strncat(cbase,base,120);

    mapinheritance(L,name,base);
    mapinheritance(L,cname,name);

    mapsuper(L,cname,cbase);
    mapsuper(L,name,base);

    lua_pushstring(L,lname);

    push_collector(L, name, col);
    /*
    luaL_getmetatable(L,name);
    lua_pushstring(L,".collector");
    lua_pushcfunction(L,col);

    lua_rawset(L,-3);
    */

    luaL_getmetatable(L,name);
    lua_rawset(L,-3);              /* assign class metatable to module */
    //ttt = lua_gettop(L);
    /* now we also need to store the collector table for the const
       instances of the class */
    push_collector(L, cname, col);
    /*
    luaL_getmetatable(L,cname);
    lua_pushstring(L,".collector");
    lua_pushcfunction(L,col);
    lua_rawset(L,-3);
    lua_pop(L,1);
     */
    //---------------- add by caspar 2013.8.22
//    lua_getmetatable(L, cname);
//    lua_pushstring(L, "__newindex");
//    lua_pushcfunction(L, __newindex);
//    lua_rawset(L, -3);
//    lua_pop(L, 1);
    //----------------

}
Пример #3
0
/* Map C class
	* It maps a C class, setting the appropriate inheritance and super classes.
*/
TOLUA_API void tolua_cclass (lua_State* L, const char* lname, const char* name, const char* base, lua_CFunction col)
{
	char cname[128] = "const ";
	char cbase[128] = "const ";

	strncat(cname,name,120);
	strncat(cbase,base,120);

	mapinheritance(L,name,base);
	mapinheritance(L,cname,name);

	if (base[0])
	{
		mapsuper(L,cname,cbase);
		mapsuper(L,name,base);
	}

	lua_pushstring(L,lname);
	
	push_collector(L, name, col);
	/*
	luaL_getmetatable(L,name);
	lua_pushstring(L,".collector");
	lua_pushcfunction(L,col);

	lua_rawset(L,-3);
	*/
	
	luaL_getmetatable(L,name);
	lua_rawset(L,-3);              /* assign class metatable to module */

	/* now we also need to store the collector table for the const
	   instances of the class */
	push_collector(L, cname, col);
	/*
	luaL_getmetatable(L,cname);
	lua_pushstring(L,".collector");
	lua_pushcfunction(L,col);
	lua_rawset(L,-3);
	lua_pop(L,1);
	*/
	

}