int push_as3_array_to_lua_stack_convert_values(lua_State * L, AS3_Val array) { LCALL(L, stack); int len = 0; int i = 0; AS3_Val cur; AS3_Val len_v; if (!AS3_InstanceOf(array, Array_class)) { LRETURN(L, stack, 0); } len_v = AS3_GetS(array, "length"); len = AS3_IntValue(len_v); SAFE_RELEASE(len_v); for (i = 0; i < len; i++) { AS3_Val i_v = AS3_Int(i); cur = AS3_Get(array, i_v); SAFE_RELEASE(i_v); push_as3_to_lua_stack(L, cur); SAFE_RELEASE(cur); } LRETURN(L, stack, len); }
int push_as3_array_to_lua_stack(lua_State * L, AS3_Val array) { LCALL(L, stack); int len = 0; int i = 0; AS3_Val cur; AS3_Val len_v; if (!AS3_InstanceOf(array, Array_class)) { LRETURN(L, stack, 0); } len_v = AS3_GetS(array, "length"); len = AS3_IntValue(len_v); SAFE_RELEASE(len_v); for (i = 0; i < len; i++) { AS3_Val i_v = AS3_Int(i); cur = AS3_Get(array, i_v); SAFE_RELEASE(i_v); /* TODO: This probably should be push_as3_to_lua_stack */ push_as3_lua_userdata(L, cur); SAFE_RELEASE(cur); } LRETURN(L, stack, len); }
//Method exposed to ActionScript //Takes a String and echos it static AS3_Val echo(void* self, AS3_Val args) { AS3_Val byteArray; AS3_ArrayValue( args, "AS3ValType", &byteArray); AS3_Val length = AS3_GetS(byteArray, "length"); sztrace("length getted!"); int len = AS3_IntValue(length); //if(len>0) return length; char *data=NULL; data=malloc(len); memset(data,0,len); int fileLen = AS3_ByteArray_readBytes(data,byteArray, len); char *out= NULL; out = malloc(fileLen); memset(out,0,fileLen); ByteArray * bytearray = ByteArray_new(fileLen); bytearray->data = data; PdfFile_free(PdfFile_parse(bytearray,out)); ByteArray_free(bytearray); return AS3_String(out); }
static AS3_Val thunk_PacketToByteArray(void *gg_clientData, AS3_Val gg_args) { AS3_Val bytes; AS3_Val packet; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &bytes, &packet); AS3_Val actionVal = AS3_GetS(packet, "action"); AS3_Val transactionIdVal = AS3_GetS(packet, "transactionId"); AS3_Val protocolVersionVal = AS3_GetS(packet, "protocolVersion"); AS3_Release(AS3_CallTS("writeByte", bytes, "IntType", AS3_IntValue(actionVal))); AS3_Release(AS3_CallTS("writeUnsignedInt", bytes, "IntType", AS3_IntValue(transactionIdVal))); AS3_Release(AS3_CallTS("writeShort", bytes, "IntType", AS3_IntValue(protocolVersionVal))); AS3_Release(actionVal); AS3_Release(transactionIdVal); AS3_Release(protocolVersionVal); AS3_Release(bytes); AS3_Release(packet); return NULL; }
static AS3_Val thunk_SubPieceRequestPacketToByteArray(void *gg_clientData, AS3_Val gg_args) { AS3_Val packet; AS3_Val bytes; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &packet, &bytes); AS3_Val subpieces = AS3_GetS(packet, "subpieces"); AS3_Val lengthVal = AS3_GetS(subpieces, "length"); AS3_Val priorityVal = AS3_GetS(packet, "priority"); AS3_Release(AS3_CallTS("writeShort", bytes, "IntType", AS3_IntValue(lengthVal))); AS3_Release(AS3_CallTS("WriteSubpieces", packet, "AS3ValType", bytes)); AS3_Release(AS3_CallTS("writeShort", bytes, "IntType", AS3_IntValue(priorityVal))); AS3_Release(subpieces); AS3_Release(lengthVal); AS3_Release(priorityVal); AS3_Release(packet); AS3_Release(bytes); return NULL; }
static AS3_Val initparam(void* self, AS3_Val args) { AS3_Val tmp = AS3_Undefined(); int il, len; for (il=0; il < sizeof(models)/sizeof(LAYER); ++il) { tmp = AS3_Get(args, AS3_Int(2*il)); len = AS3_IntValue(AS3_GetS(tmp, "length")); models[il].w = (float*) malloc(len); AS3_ByteArray_readBytes(models[il].w, tmp, len); tmp = AS3_Get(args, AS3_Int(2*il+1)); len = AS3_IntValue(AS3_GetS(tmp, "length")); models[il].b = (float*) malloc(len); AS3_ByteArray_readBytes(models[il].b, tmp, len); } data = (float*) malloc(BUF_SIZE); o = (float*) malloc(BUF_SIZE); return AS3_Int(0); }
AS3_Val initializeFog( void* self, AS3_Val args ) { Fog * fog; AS3_Val color; double a, r, g, b, density, start, end; int mode; AS3_ArrayValue( args, "AS3ValType, DoubleType, DoubleType, DoubleType, IntType", & color, & start, & end, & density, & mode ); r = AS3_NumberValue( AS3_GetS( color, "redMultiplier" ) ); g = AS3_NumberValue( AS3_GetS( color, "greenMultiplier" ) ); b = AS3_NumberValue( AS3_GetS( color, "blueMultiplier" ) ); a = AS3_NumberValue( AS3_GetS( color, "alphaMultiplier" ) ); fog = newFog( newColorValue( (float)r, (float)g, (float)b, (float)a ), (float)start, (float)end, (float)density, mode ); AS3_Release( color ); return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", fog, fog->global, & fog->start, & fog->end, & fog->density, & fog->mode ); }
// Go check a Flash event queue for events SDL should be aware of! void FLASH_PumpEvents(_THIS) { if (!FLASH_EMPTY_PARAMS) FLASH_EMPTY_PARAMS = AS3_Array(""); // Event Vars AS3_Val mouseEvent, mouseEvents, mousePosition, keyboardEvent, keyboardEvents; int buttonState, rawKeyboardEvent, scanCode, keyState; SDL_keysym keysym; mousePosition = AS3_CallS( "pumpMousePosition", FLASH_EVENT_MANAGER_OBJECT, FLASH_EMPTY_PARAMS ); mouseEvents = AS3_CallS( "pumpMouseEvents", FLASH_EVENT_MANAGER_OBJECT, FLASH_EMPTY_PARAMS ); keyboardEvents = AS3_CallS( "pumpKeyEvents", FLASH_EVENT_MANAGER_OBJECT, FLASH_EMPTY_PARAMS ); // Mouse Position if (mousePosition) { AS3_ObjectValue( mousePosition, "x:IntType, y:IntType", &FLASH_mouseX, &FLASH_mouseY ); SDL_PrivateMouseMotion( 0, 0, FLASH_mouseX, FLASH_mouseY ); } // Mouse Click Events while( AS3_IntValue(AS3_GetS(mouseEvents, "size")) > 0 ) { mouseEvent = AS3_CallS( "dequeue", mouseEvents, FLASH_EMPTY_PARAMS ); buttonState = AS3_IntValue( mouseEvent )? SDL_PRESSED: SDL_RELEASED; SDL_PrivateMouseButton(buttonState, SDL_BUTTON_LEFT, FLASH_mouseX, FLASH_mouseY); } // Keyboard Events while( AS3_IntValue(AS3_GetS(keyboardEvents, "size")) > 0 ) { keyboardEvent = AS3_CallS( "dequeue", keyboardEvents, FLASH_EMPTY_PARAMS ); rawKeyboardEvent = AS3_IntValue( keyboardEvent ); scanCode = rawKeyboardEvent & 0xFF; // Packed event format: 9th bit for press/release, lower 8 bits for scan code keyState = rawKeyboardEvent >> 8; SDL_PrivateKeyboard(keyState, TranslateKey(scanCode, &keysym)); } }
static AS3_Val thunk_InitBlockMap(void *gg_clientData, AS3_Val gg_args) { AS3_Val map; AS3_Val bytes; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &map, &bytes); AS3_Val blockCountVal = AS3_CallTS("readUnsignedInt", bytes, ""); AS3_Val bitset = AS3_GetS(map, "bitset"); AS3_SetS(map, "blockCount", blockCountVal); AS3_Release(AS3_CallTS("readBytes", bytes, "AS3ValType, IntType, IntType", bitset, 0, (int)((AS3_IntValue(blockCountVal) + 7) / 8))); AS3_Release(blockCountVal); AS3_Release(bitset); AS3_Release(map); AS3_Release(bytes); return NULL; }
static AS3_Val thunk_InitSubPiecePacket(void *gg_clientData, AS3_Val gg_args) { AS3_Val packet; AS3_Val bytes; AS3_ArrayValue(gg_args, "AS3ValType, AS3ValType", &packet, &bytes); AS3_Val subpiece = AS3_GetS(packet, "subpiece"); AS3_Val blockIndexVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_Val subPieceIndexVal = AS3_CallTS("readUnsignedShort", bytes, ""); AS3_SetS(subpiece, "blockIndex", blockIndexVal); AS3_SetS(subpiece, "subPieceIndex", subPieceIndexVal); AS3_Release(subpiece); AS3_Release(blockIndexVal); AS3_Release(subPieceIndexVal); AS3_Release(packet); AS3_Release(bytes); return NULL; }
AS3_Val initializeMaterial( void* self, AS3_Val args ) { Material * material; AS3_Val ambient, diffuse, specular, emissive; double a_a, a_r, a_g, a_b, d_a, d_r, d_g, d_b, s_a, s_r, s_g, s_b, e_a, e_r, e_g, e_b, power; AS3_ArrayValue( args, "AS3ValType, AS3ValType, AS3ValType, AS3ValType, DoubleType", &ambient, &diffuse, &specular, &emissive, &power ); a_r = AS3_NumberValue( AS3_GetS( ambient, "redMultiplier" ) ); a_g = AS3_NumberValue( AS3_GetS( ambient, "greenMultiplier" ) ); a_b = AS3_NumberValue( AS3_GetS( ambient, "blueMultiplier" ) ); a_a = AS3_NumberValue( AS3_GetS( ambient, "alphaMultiplier" ) ); d_r = AS3_NumberValue( AS3_GetS( diffuse, "redMultiplier" ) ); d_g = AS3_NumberValue( AS3_GetS( diffuse, "greenMultiplier" ) ); d_b = AS3_NumberValue( AS3_GetS( diffuse, "blueMultiplier" ) ); d_a = AS3_NumberValue( AS3_GetS( diffuse, "alphaMultiplier" ) ); s_r = AS3_NumberValue( AS3_GetS( specular, "redMultiplier" ) ); s_g = AS3_NumberValue( AS3_GetS( specular, "greenMultiplier" ) ); s_b = AS3_NumberValue( AS3_GetS( specular, "blueMultiplier" ) ); s_a = AS3_NumberValue( AS3_GetS( specular, "alphaMultiplier" ) ); e_r = AS3_NumberValue( AS3_GetS( emissive, "redMultiplier" ) ); e_g = AS3_NumberValue( AS3_GetS( emissive, "greenMultiplier" ) ); e_b = AS3_NumberValue( AS3_GetS( emissive, "blueMultiplier" ) ); e_a = AS3_NumberValue( AS3_GetS( emissive, "alphaMultiplier" ) ); material = newMaterial( newColor888( (BYTE)(a_r * 255), (BYTE)(a_g * 255), (BYTE)(a_b * 255), (BYTE)(a_a * 255) ), newColor888( (BYTE)(d_r * 255), (BYTE)(d_g * 255), (BYTE)(d_b * 255), (BYTE)(d_a * 255) ), newColor888( (BYTE)(s_r * 255), (BYTE)(s_g * 255), (BYTE)(s_b * 255), (BYTE)(s_a * 255) ), newColor888( (BYTE)(e_r * 255), (BYTE)(e_g * 255), (BYTE)(e_b * 255), (BYTE)(e_a * 255) ), power ); AS3_Release( ambient ); AS3_Release( diffuse ); AS3_Release( specular ); AS3_Release( emissive ); return AS3_Array( "PtrType, PtrType, PtrType, PtrType, PtrType, PtrType, PtrType", material, material->ambient, material->diffuse, material->specular, material->emissive, &material->power, &material->doubleSide ); }