Quaternion QuaternionExtract(Handle<Object>& src) { Quaternion result( NumericExtract( src->Get(JS_STRING(x)) ), NumericExtract( src->Get(JS_STRING(y)) ), NumericExtract( src->Get(JS_STRING(z)) ), NumericExtract( src->Get(JS_STRING(w)) ), Quaternion::XYZW() ); return result; }
bool QuaternionValidate(Handle<Object>& src) { return ( src->Has(JS_STRING(x)) && NumericValidate(src->Get(JS_STRING(x))) && src->Has(JS_STRING(y)) && NumericValidate(src->Get(JS_STRING(y))) && src->Has(JS_STRING(z)) && NumericValidate(src->Get(JS_STRING(z))) && src->Has(JS_STRING(w)) && NumericValidate(src->Get(JS_STRING(w))) ); }
Handle<Value> CreateJSResult(v8::Handle<v8::Context>& ctx, const Quaternion& src) { Handle<Function> quat_constructor = FunctionCast( ObjectCast(GetGlobal(ctx, JSSystemNames::UTIL_OBJECT_NAME))->Get(JS_STRING(Quaternion)) ); Handle<Object> result = quat_constructor->NewInstance(); QuaternionFill(result, src); return result; }
CEJsValue js_to_cejs_value(duk_context* ctx, int index) { if (duk_is_number(ctx, index)) return JS_NUMBER(duk_to_number(ctx, index)); if (duk_is_boolean(ctx, index)) return JS_BOOL(duk_to_boolean(ctx, index)); if (duk_is_string(ctx, index)) return JS_STRING(duk_to_string(ctx, index)); if (duk_is_array(ctx, index)) return JS_STRING(duk_json_encode(ctx, index)); if (duk_is_object(ctx, index)) return JS_STRING(duk_json_encode(ctx, index)); if (duk_is_undefined(ctx, index)) { return JS_UNDEFINED; } return JS_NULL; }
Handle<FunctionTemplate> CreateQuaternionTemplate() { // Quaternion Constructor Local<FunctionTemplate> quat_constructor_templ = FunctionTemplate::New(QuaternionConstructor); QuaternionConstructorTemplate = Persistent<FunctionTemplate>::New(quat_constructor_templ); // Quaternion prototype Local<ObjectTemplate> quat_prototype_templ = quat_constructor_templ->PrototypeTemplate(); quat_prototype_templ->Set(JS_STRING(toString), v8::FunctionTemplate::New(QuaternionToString)); // Quaternion instance Local<ObjectTemplate> quat_instance_templ = quat_constructor_templ->InstanceTemplate(); return quat_constructor_templ; }
case JS_NULL_TAG: return false; case JS_UNDEFINED_TAG: return false; default: return true; } } JS_LT_VARIANT(NUMBER_NUMBER, a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG, a.number < b.number, JSValue_NUMBER(a) < JSValue_NUMBER(b)); JS_EQ_VARIANT(NUMBER_NUMBER, a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG, a.number == b.number, JSValue_NUMBER(a) == JSValue_NUMBER(b)); JS_OR_VARIANT(BOOL_BOOL, a.tag == JS_BOOL_TAG && b.tag == JS_BOOL_TAG, a.boolean || b.boolean, JSValue_BOOL(a) || JSValue_BOOL(b)); JS_ADD_VARIANT(INT_INT, a.tag == JS_INT_TAG && b.tag == JS_INT_TAG, JS_NUMBER(a.integer + b.integer), JS_ADD_DOUBLE_DOUBLE(a, b)); JS_ADD_VARIANT(DOUBLE_DOUBLE, a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG, JS_NUMBER(a.number + b.number), JS_ADD_NUMBER_NUMBER(a, b)); JS_ADD_VARIANT(NUMBER_NUMBER, (a.tag == JS_INT_TAG || a.tag == JS_NUMBER_TAG) && (b.tag == JS_INT_TAG || b.tag == JS_NUMBER_TAG), JS_NUMBER(JSValue_NUMBER(a) + JSValue_NUMBER(b)), JS_ADD_DOUBLE_STRING(a, b)); JS_ADD_VARIANT(DOUBLE_STRING, a.tag == JS_NUMBER_TAG && b.tag == JS_STRING_TAG, JS_STRING(HPRINTF("%f%s", a.number, b.string)), JS_ADD_STRING_STRING(a, b)); JS_ADD_VARIANT(STRING_STRING, a.tag == JS_STRING_TAG && b.tag == JS_STRING_TAG, JS_STRING(HPRINTF("%s%s", a.string, b.string)), JS_STRING(HPRINTF("%s%s", JSValue_STR(a), JSValue_STR(b)))); JS_SUB_VARIANT(DOUBLE_DOUBLE, a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG, JS_NUMBER(a.number - b.number), JS_NUMBER(JSValue_NUMBER(a) - JSValue_NUMBER(b))); JS_MUL_VARIANT(DOUBLE_DOUBLE, a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG, JS_NUMBER(a.number * b.number), JS_NUMBER(JSValue_NUMBER(a) * JSValue_NUMBER(b))); JS_DIV_VARIANT(DOUBLE_DOUBLE, a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG, JS_NUMBER(a.number / b.number), JS_NUMBER(JSValue_NUMBER(a) / JSValue_NUMBER(b))); JS_MOD_VARIANT(INT_INT, a.tag == JS_INT_TAG && b.tag == JS_INT_TAG, JS_NUMBER(a.integer % b.integer), JS_MOD_DOUBLE_DOUBLE(a, b)); JS_MOD_VARIANT(DOUBLE_DOUBLE, a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG, JS_NUMBER(fmod(a.number, b.number)), JS_NUMBER(fmod(JSValue_NUMBER(a), JSValue_NUMBER(b)))); /** * Globals */
if (a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG) { *op_cache_ptr = &JS_EQ_NUMBER_NUMBER; } return ((js_op_ptr) *op_cache_ptr)(op_cache_ptr, a, b); } JS_OR_VARIANT(BOOL_BOOL, a.tag != b.tag, a.number || b.number); bool JS_OR_SWITCH (void **op_cache_ptr, JSValue a, JSValue b) { if (a.tag == JS_BOOL_TAG && b.tag == JS_BOOL_TAG) { *op_cache_ptr = &JS_OR_BOOL_BOOL; } return ((js_op_ptr) *op_cache_ptr)(op_cache_ptr, a, b); } JS_ADD_VARIANT(DOUBLE_DOUBLE, a.tag != b.tag, JS_NUMBER(a.number + b.number)); JS_ADD_VARIANT(DOUBLE_STRING, a.tag != JS_NUMBER_TAG || b.tag != JS_STRING_TAG, JS_STRING(HPRINTF("%f%s", a.number, b.string))); JSValue JS_ADD_SWITCH (void **op_cache_ptr, JSValue a, JSValue b) { if (a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG) { *op_cache_ptr = &JS_ADD_DOUBLE_DOUBLE; } else if (a.tag == JS_NUMBER_TAG && b.tag == JS_STRING_TAG) { *op_cache_ptr = &JS_ADD_DOUBLE_STRING; } return ((jsvalue_op_ptr) *op_cache_ptr)(op_cache_ptr, a, b); } JS_SUB_VARIANT(DOUBLE_DOUBLE, a.tag != b.tag, JS_NUMBER(a.number - b.number)); JSValue JS_SUB_SWITCH (void **op_cache_ptr, JSValue a, JSValue b) { if (a.tag == JS_NUMBER_TAG && b.tag == JS_NUMBER_TAG) { *op_cache_ptr = &JS_SUB_DOUBLE_DOUBLE; } return ((jsvalue_op_ptr) *op_cache_ptr)(op_cache_ptr, a, b);
void QuaternionFill(Handle<Object>& dest, const Quaternion& src) { dest->Set(JS_STRING(x), Number::New(src.x)); dest->Set(JS_STRING(y), Number::New(src.y)); dest->Set(JS_STRING(z), Number::New(src.z)); dest->Set(JS_STRING(w), Number::New(src.w)); }