Example #1
0
//----------------------------------------------------------------//
bool MOAILuaState::Encode ( int idx, USStreamWriter& writer ) {

	if ( !this->IsType ( idx, LUA_TSTRING )) return false;

	size_t len;
	cc8* buffer = lua_tolstring ( this->mState, idx, &len );
	if ( !len ) return false;
	
	USMemStream stream;
	
	writer.Open ( &stream );
	writer.WriteBytes ( buffer, len );
	writer.Close ();
	
	len = stream.GetLength ();
	void* temp = malloc ( len );
	
	stream.Seek ( 0, SEEK_SET );
	stream.ReadBytes (( void* )temp, len );
	
	lua_pushlstring ( this->mState, ( cc8* )temp, len );
	
	free ( temp );
	
	return true;
}
Example #2
0
//----------------------------------------------------------------//
bool USData::Encode ( USStreamWriter& writer ) {

    this->mMutex.Lock ();

    USMemStream stream;

    writer.Open ( &stream );
    writer.WriteBytes ( this->mBytes, this->mBytes.Size ());
    writer.Close ();

    size_t len = stream.GetLength ();
    this->mBytes.Init ( len );

    stream.Seek ( 0, SEEK_SET );
    stream.ReadBytes ( this->mBytes, len );

    this->mMutex.Unlock ();
    return true;
}