コード例 #1
0
//----------------------------------------------------------------//
uintptr MOAISerializer::AffirmMemberID ( MOAILuaState& state, int idx ) {

	// if we're an object, affirm as such...
	if ( state.IsType ( idx, LUA_TUSERDATA )) {
		return this->AffirmMemberID ( state.GetLuaObject < MOAILuaObject >( -1 ));
	}

	// bail if we're not a table
	if ( !state.IsType ( idx, LUA_TTABLE )) return 0;

	// get the table's address
	uintptr memberID = ( uintptr )lua_topointer ( state, idx );
	
	// bail if the table's already been added
	if ( this->mTableMap.contains ( memberID )) return memberID;

	// add the ref now to avoid cycles
	this->mTableMap [ memberID ].SetStrongRef ( state, idx );

	// follow the table's refs to make sure everything gets added
	u32 itr = state.PushTableItr ( idx );
	while ( state.TableItrNext ( itr )) {
		this->AffirmMemberID ( state, -1 );
	}
	
	return memberID;
}
コード例 #2
0
ファイル: MOAIGlyphSet.cpp プロジェクト: Inzaghi2012/moai-dev
//----------------------------------------------------------------//
void MOAIGlyphSet::SerializeIn ( MOAILuaState& state ) {
	UNUSED ( state );
	
	this->mSize		= state.GetField ( -1, "mSize", this->mSize );
	this->mHeight	= state.GetField ( -1, "mHeight", this->mHeight );
	this->mAscent	= state.GetField ( -1, "mAscent", this->mAscent );

	if ( state.GetFieldWithType ( -1, "mGlyphMap", LUA_TTABLE )) {

		u32 itr = state.PushTableItr ( -1 );
		while ( state.TableItrNext ( itr )) {
			u32 c = state.GetValue < u32 >( -2, 0 );
			MOAIGlyph& glyph = this->mGlyphMap [ c ];
			glyph.SerializeIn ( state );
		}
		state.Pop ( 1 );
	}
	
	GlyphMapIt glyphMapIt = this->mGlyphMap.begin ();
	for ( ; glyphMapIt != this->mGlyphMap.end (); ++glyphMapIt ) {
		MOAIGlyph& glyph = glyphMapIt->second;
		
		if ( glyph.mPageID == MOAIGlyph::NULL_PAGE_ID ) {
			glyph.mNext = this->mPending;
			this->mPending = &glyph;
		}
		else {
			glyph.mNext = this->mGlyphs;
			this->mGlyphs = &glyph;
		}
	}
}
コード例 #3
0
//----------------------------------------------------------------//
json_t* _luaToJSONObject ( lua_State* L, int idx ) {

    MOAILuaState state ( L );
    json_t* object = json_object ();

    u32 itr = state.PushTableItr ( idx );
    while ( state.TableItrNext ( itr )) {

        if ( lua_type ( state, -2 ) != LUA_TSTRING ) continue;

        STLString key = lua_tostring ( state, -2 );

        json_t* value = _luaToJSON ( state, -1 );

        if ( value ) {
            json_object_set_new ( object, key, value );
        }
    }
    return object;
}
コード例 #4
0
//----------------------------------------------------------------//
u32 MOAISerializer::WriteTableInitializer ( USStream& stream, MOAILuaState& state, int idx, cc8* prefix ) {

	u32 count = 0;
	u32 itr = state.PushTableItr ( idx );
	while ( state.TableItrNext ( itr )) {
		
		int keyType = lua_type ( state, -2 );
		int valType = lua_type ( state, -1 );
		cc8* keyName = lua_tostring ( state, -2 );
		
		switch ( valType ) {
			case LUA_TNONE:
			case LUA_TNIL:
			case LUA_TFUNCTION:
			case LUA_TUSERDATA:
			case LUA_TTHREAD:
				continue;
		}
		
		switch ( keyType ) {
		
			case LUA_TSTRING: {
				stream.Print ( "\t%s [ \"%s\" ] = ", prefix, keyName );
				break;
			}
			case LUA_TNUMBER: {
				stream.Print ( "\t%s [ %s ]\t= ", prefix, keyName );
				break;
			}
		};
		
		switch ( valType ) {
			
			case LUA_TBOOLEAN: {
				int value = lua_toboolean ( state, -1 );
				cc8* str = ( value ) ? "true": "false";
				stream.Print ( "%s\n", str );
				break;
			}
			case LUA_TTABLE: {
				uintptr tableID = ( uintptr )lua_topointer ( state, -1 );
				if ( this->mTableMap.contains ( tableID )) {
					stream.Print ( "objects [ 0x%08X ]\n", tableID );
				}
				break;
			}
			case LUA_TSTRING: {
				STLString str = _escapeString ( lua_tostring ( state, -1 ));
				stream.Print ( "\"%s\"\n", str.c_str ());
				break;
			}
			case LUA_TNUMBER: {
				stream.Print ( "%s\n", lua_tostring ( state, -1 ));
				break;
			}
			case LUA_TUSERDATA: {
				MOAILuaObject* object = state.GetLuaObject < MOAILuaObject >( -1 );
				u32 instanceID = this->GetID ( object );
				stream.Print ( "objects [ 0x%08X ]\n", instanceID );
				break;
			}
			case LUA_TLIGHTUSERDATA: {
				stream.Print ( "%p,\n", lua_touserdata ( state, -1 ));
				break;
			}
		};
		
		++count;
	}
	
	return count;
}
コード例 #5
0
//----------------------------------------------------------------//
u32 MOAISerializer::WriteTable ( USStream& stream, MOAILuaState& state, int idx, u32 tab ) {

	STLString indent;
	
	for ( u32 i = 0; i < tab; ++i ) {
		indent.append ( "\t" );
	}
	
	u32 count = 0;
	u32 itr = state.PushTableItr ( idx );
	while ( state.TableItrNext ( itr )) {
		
		int keyType = lua_type ( state, -2 );
		int valType = lua_type ( state, -1 );
		cc8* keyName = lua_tostring ( state, -2 );
		
		switch ( valType ) {
			case LUA_TNONE:
			case LUA_TNIL:
			case LUA_TFUNCTION:
			case LUA_TUSERDATA:
			case LUA_TTHREAD:
				continue;
		}
		
		if ( count == 0 ) {
			stream.Print ( "\n" );
		}
		
		switch ( keyType ) {
		
			case LUA_TSTRING: {
				stream.Print ( "%s[ \"%s\" ] = ", indent.c_str (), keyName );
				break;
			}
			case LUA_TNUMBER: {
				stream.Print ( "%s[ %s ]\t= ", indent.c_str (), keyName );
				break;
			}
		};
		
		switch ( valType ) {
			
			case LUA_TBOOLEAN: {
				int value = lua_toboolean ( state, -1 );
				cc8* str = ( value ) ? "true": "false";
				stream.Print ( "%s,\n", str );
				break;
			}
			case LUA_TTABLE: {
				
				uintptr tableID = ( uintptr )lua_topointer ( state, -1 );
				if ( this->mTableMap.contains ( tableID )) {
					stream.Print ( "objects [ 0x%08X ],\n", tableID );
				}
				else {
					stream.Print ( "{" );
					if ( this->WriteTable ( stream, state, -1, tab + 1 )) {
						stream.Print ( "%s},\n", indent.c_str ());
					}
					else {
						stream.Print ( "},\n" );
					}
				}
				break;
			}
			case LUA_TSTRING: {
				STLString str = _escapeString ( lua_tostring ( state, -1 ));
				stream.Print ( "\"%s\",\n", str.c_str ());
				break;
			}
			case LUA_TNUMBER: {
				stream.Print ( "%s,\n", lua_tostring ( state, -1 ));
				break;
			}
			case LUA_TLIGHTUSERDATA: {
				stream.Print ( "%p,\n", lua_touserdata ( state, -1 ));
				break;
			}
		};
		
		++count;
	}
	
	return count;
}