Ejemplo n.º 1
0
//----------------------------------------------------------------//
bool MOAILuaState::Encode ( int idx, ZLStreamWriter& writer ) {

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

	size_t len;
	cc8* buffer = lua_tolstring ( this->mState, idx, &len );
	if ( !len ) return false;
	
	ZLMemStream 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;
}
Ejemplo n.º 2
0
//----------------------------------------------------------------//
bool MOAILuaState::Decode ( int idx, ZLStreamReader& reader ) {

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

	size_t len;
	void* buffer = ( void* )lua_tolstring ( this->mState, idx, &len );
	if ( !len ) return false;
	
	ZLByteStream cryptStream;
	cryptStream.SetBuffer ( buffer, len );
	cryptStream.SetLength ( len );
	
	ZLMemStream plainStream;
	
	reader.Open ( cryptStream );
	plainStream.WriteStream ( reader );
	reader.Close ();
	
	len = plainStream.GetLength ();
	buffer = malloc ( len );
	
	plainStream.Seek ( 0, SEEK_SET );
	plainStream.ReadBytes ( buffer, len );
	
	lua_pushlstring ( this->mState, ( cc8* )buffer, len );
	
	free ( buffer );
	
	return true;
}
Ejemplo n.º 3
0
//----------------------------------------------------------------//
void STLString::zl_encode ( ZLStreamAdapter& writer, const void* buffer, size_t len ) {

	( *this ) = "";
	if ( !len ) return;
	
	ZLMemStream memStream;
	
	writer.Open ( &memStream );
	writer.WriteBytes ( buffer, len );
	writer.Close ();
	
	memStream.Seek ( 0, SEEK_SET );
	( *this ) = memStream.ReadString ( memStream.GetLength ());
}
Ejemplo n.º 4
0
/**	@name	toCppHeader
	@text	Convert data to CPP header file.

	@overload

		@in		string data				The string data to encode
		@in		string name
		@opt	number columns			Default value is 12
		@out	string output
	
	@overload

		@in		MOAIDataBuffer data		The data buffer to encode
		@in		string name
		@opt	number columns			Default value is 12
		@out	string output
*/
int MOAIDataBuffer::_toCppHeader ( lua_State* L ) {
	MOAILuaState state ( L );
	
	cc8* name		= state.GetValue < cc8* >( 2, "" );
	u32 columns		= state.GetValue < u32 >( 3, 12 );
	
	if ( !strlen ( name )) return 0;
	
	ZLMemStream memStream;
	
	if ( state.IsType ( 1, LUA_TSTRING )) {
		
		size_t size;
		const void* bytes = lua_tolstring ( state, 1, &size );
		ZLHexDump::DumpAsCPPHeader ( memStream, name, bytes, size, columns );
	}
	
	MOAIDataBuffer* dataBuffer = state.GetLuaObject < MOAIDataBuffer >( 1, true );
	if ( dataBuffer ) {
		
		size_t size;
		void* bytes;
		dataBuffer->Lock ( &bytes, &size );
		ZLHexDump::DumpAsCPPHeader ( memStream, name, bytes, size, columns );
	}
	
	if ( memStream.GetLength ()) {
		
		memStream.Seek ( 0, SEEK_SET );
		STLString result = memStream.ReadString ( memStream.GetLength ());
		
		lua_pushstring ( state, result );
		return 1;
	}
	return 0;
}
Ejemplo n.º 5
0
//----------------------------------------------------------------//
bool MOAIDataBuffer::Encode ( ZLStreamWriter& writer ) {
	
	this->mMutex.Lock ();
	
	ZLMemStream 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;
}
Ejemplo n.º 6
0
//----------------------------------------------------------------//
bool MOAIDataBuffer::Decode ( ZLStreamReader& reader ) {
	
	this->mMutex.Lock ();
	
	ZLByteStream cryptStream;
	cryptStream.SetBuffer ( this->mBytes, this->mBytes.Size ());
	cryptStream.SetLength ( this->mBytes.Size ());
	
	ZLMemStream plainStream;
	
	reader.Open ( cryptStream );
	plainStream.WriteStream ( reader );
	reader.Close ();
	
	size_t len = plainStream.GetLength ();
	this->mBytes.Init ( len );
	
	plainStream.Seek ( 0, SEEK_SET );
	plainStream.ReadBytes ( this->mBytes, len );
	
	this->mMutex.Unlock ();
	return true;
}
Ejemplo n.º 7
0
//----------------------------------------------------------------//
void SafeTesselator::GetTriangles ( MOAIVertexBuffer& vtxBuffer, MOAIIndexBuffer& idxBuffer ) {

	ZLMemStream idxStream;
	ZLMemStream vtxStream;

	const int* elems = tessGetElements ( this->mTess );
	const int nelems = tessGetElementCount ( this->mTess );
	
	for ( int i = 0; i < nelems; ++i ) {
		const int* tri = &elems [ i * 3 ];
		
		idxStream.Write < u32 >( tri [ 0 ]);
		idxStream.Write < u32 >( tri [ 1 ]);
		idxStream.Write < u32 >( tri [ 2 ]);
	}

	const float* verts = tessGetVertices ( this->mTess );
	const int nverts = tessGetVertexCount ( this->mTess );
	
	for ( int i = 0; i < nverts; ++i ) {
		const ZLVec2D& vert = (( const ZLVec2D* )verts )[ i ];
		
		vtxStream.Write < float >( vert.mX );
		vtxStream.Write < float >( vert.mY );
		vtxStream.Write < float >( 0.0f );
		vtxStream.Write < u32 >( 0xffffffff );
	}
	
	idxStream.Seek ( 0, SEEK_SET );
	vtxStream.Seek ( 0, SEEK_SET );
	
	idxBuffer.CopyFromStream ( idxStream, 4 );
	
	vtxBuffer.Clear ();
	vtxBuffer.Reserve ( vtxStream.GetLength ());
	vtxBuffer.WriteStream ( vtxStream );
}