示例#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, char* lname, char* name, 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);
    luaL_getmetatable(L,name);
    lua_pushstring(L,".collector");
    lua_pushcfunction(L,col);

    lua_rawset(L,-3);              /* store collector function into metatable */
    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 */
    luaL_getmetatable(L,cname);
    lua_pushstring(L,".collector");
    lua_pushcfunction(L,col);
    lua_rawset(L,-3);
    lua_pop(L,1);                  /* get rid of metatable for const object */

}
示例#2
0
/* Add base
    * It adds additional base classes to a class (for multiple inheritance)
    * (not for now)
    */
TOLUA_API void tolua_addbase(lua_State* L, char* name, char* base) {

    char cname[128] = "const ";
    char cbase[128] = "const ";
    strncat(cname,name,120);
    strncat(cbase,base,120);

    mapsuper(L,cname,cbase);
    mapsuper(L,name,base);
};
示例#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)
{
    // 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);
    */


}
示例#4
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);
    //----------------

}
示例#5
0
/* 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' */
}
示例#6
0
/* Map C class
	* It maps a C class, setting the appropriate inheritance and super classes.
*/
TOLUA_API void tolua_cclass (lua_State* L, char* lname, char* name, 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);    
	luaL_getmetatable(L,name);
	lua_pushstring(L,".collector");
	lua_pushcfunction(L,col);
	lua_rawset(L,-3);              /* store collector function into metatable */
	lua_rawset(L,-3);              /* assign class metatable to module */
}
示例#7
0
TOLUA_API void tolua_mapsuper (lua_State* L, const char* name, const char* base)
{
	mapsuper(L,name,base);
}