#include #include #include "AS3.h" //Method exposed to ActionScript //Takes a String and echos it static AS3_Val invSqrt(void* self, AS3_Val args) { double xx; float x; //parse the arguments. Expect 1. //pass in val to hold the first argument, which //should be a string AS3_ArrayValue( args, "DoubleType", &xx ); x = (float)xx; float xhalf = 0.5f*x; int i = *(int*)&x; i = 0x5f3759df - (i>>1); x = *(float*)&i; x = x*(1.5f - xhalf*x*x); return AS3_Number( x ); } int main() { //define the methods exposed to ActionScript //typed as an ActionScript Function instance AS3_Val invsqrtMethod = AS3_Function( NULL, invSqrt ); // construct an object that holds references to the functions AS3_Val result = AS3_Object( "invSqrt:AS3ValType", invsqrtMethod ); // Release AS3_Release( invsqrtMethod ); // notify that we initialized -- THIS DOES NOT RETURN! AS3_LibInit( result ); // should never get here! return 0; }