コード例 #1
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 ());
}
コード例 #2
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;
}