示例#1
0
文件: ScriptLua.cpp 项目: berak/e6
	void class_start(lua_State * L, const char * clsName, const char * superName, int classID, SCRIPT_CALLBACK ctor)
	{
		clsTop = lua_gettop(L);
		clsMap [ classID ] = clsName;

		push_method( L, clsName, ctor, 1 );

		_newmetatable( L, clsName );
	
		if ( superName ) // copy all inherited members to 'this' metatable
		{
			int c = lua_gettop(L);
			lua_pushstring( L, superName );
			lua_gettable( L, LUA_REGISTRYINDEX );

		    lua_pushnil(L);  // first key 
			while (lua_next(L, -2) != 0) 
			{
				// don't copy __index & __gc, etc:
				if ( strstr( lua_tostring(L,-2), "__" ) )
				{
			        lua_pop(L, 1);  // removes `value'; keeps `key' for next iteration 
					continue;
				}
				lua_pushvalue( L,  c ); // the table
				lua_pushvalue( L, -3 ); // the key
				lua_pushvalue( L, -3 ); // the value
				lua_settable( L, -3 );  // set table
		        lua_pop(L, 1);  // removes table
		        lua_pop(L, 1);  // removes `value'; keeps `key' for next iteration 
		    }
			lua_settop(L,c);
		}
	}
示例#2
0
文件: luas.cpp 项目: lvshaco/luas
int luas_reg_global(luas_state* s, const char* mod, const luaL_Reg* funcs, int func_count) {
    lua_State* L = s->l;
    lua_pushlightuserdata(L, NULL);
    _newmetatable(L, mod, funcs, func_count);
    lua_setmetatable(L, -2);
    lua_pop(L, 1);
    return 0;
}
示例#3
0
文件: luas.cpp 项目: lvshaco/luas
int luas_reg_module(luas_state* s, const char* mod, const luaL_Reg* funcs, int func_count) {
    lua_State* L = s->l;
    _newmetatable(L, mod, funcs, func_count);
    lua_pop(L, 1);
    return 0;
}