-
-
Save nakula/65d3c7ff683b326ecd22 to your computer and use it in GitHub Desktop.
flashzlib sample
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "AS3.h" | |
#include <stdio.h> | |
#include "zlib.h" | |
#ifdef STDC | |
# include <string.h> | |
# include <stdlib.h> | |
#endif | |
#define CHECK_ERR(err, msg) { \ | |
if (err != Z_OK) { \ | |
fprintf(stderr, "%s error: %d\n", msg, err); \ | |
exit(1); \ | |
} \ | |
} | |
static AS3_Val returnString(void* self, AS3_Val args) | |
{ | |
int err = 0; | |
int len; | |
// int runner = 0; | |
AS3_Val compr_as3 = AS3_Undefined(); | |
AS3_ArrayValue(args, "AS3ValType, IntType", &compr_as3, &len); | |
Byte *compr; | |
compr = (Byte*)calloc((uInt)len, 1); | |
AS3_ByteArray_seek(compr_as3, 0, SEEK_SET); | |
// for(runner=0; runner < len; runner++) { | |
// *(compr + runner) = AS3_IntValue(AS3_Get(compr_as3, AS3_Int(runner))) & 0xFF; | |
// } | |
AS3_ByteArray_readBytes(compr, compr_as3, len); | |
Byte *uncompr; | |
uLong uncomprLen = 40000*sizeof(Byte); /* don't overflow on MSDOS */ | |
uncompr = (Byte*)calloc((uInt)uncomprLen, 1); | |
z_stream d_stream; /* decompression stream */ | |
// strcpy((char*)uncompr, "garbage"); | |
d_stream.zalloc = (alloc_func)0; | |
d_stream.zfree = (free_func)0; | |
d_stream.opaque = (voidpf)0; | |
d_stream.next_in = compr; | |
d_stream.avail_in = (uInt)len; | |
err = inflateInit(&d_stream); | |
// FAILs HERE | |
return AS3_Int(err); | |
for (;;) { | |
d_stream.next_out = uncompr; /* discard the output */ | |
d_stream.avail_out = (uInt)uncomprLen; | |
err = inflate(&d_stream, Z_NO_FLUSH); | |
if (err == Z_STREAM_END) break; | |
//CHECK_ERR(err, "large inflate"); | |
} | |
err = inflateEnd(&d_stream); | |
//CHECK_ERR(err, "inflateEnd"); | |
// err = uncompress(uncompr, &uncomprLen, compr, len); | |
return AS3_Int(uncomprLen); | |
// CHECK_ERR(err, "uncompress"); | |
// AS3_ByteArray_writeBytes(dst, uncompr, uncomprLen); | |
char* text = "Hello World"; | |
return AS3_String(text); | |
} | |
int main() | |
{ | |
AS3_Val cMethod = AS3_Function( NULL, returnString ); | |
AS3_Val result = AS3_Object( "returnString : AS3ValType" , cMethod); | |
AS3_Release( cMethod ); | |
AS3_LibInit( result ); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment