Made JS Vector/Quaternion array integration more lax about types, specifically because numbers in OpenStep-format property lists are actually strings and will be bridged to JS as such.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@1220 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2007-10-16 17:54:44 +00:00
parent 3072399a41
commit 0b678c996c
2 changed files with 18 additions and 31 deletions

View File

@ -221,23 +221,16 @@ BOOL JSObjectGetQuaternion(JSContext *context, JSObject *quaternionObj, Quaterni
JS_LookupElement(context, quaternionObj, 2, &arrayY) &&
JS_LookupElement(context, quaternionObj, 3, &arrayZ))
{
// ...and all four elements are numbers...
if (JSVAL_IS_NUMBER(arrayW) &&
JSVAL_IS_NUMBER(arrayX) &&
JSVAL_IS_NUMBER(arrayY) &&
JSVAL_IS_NUMBER(arrayZ))
{
// Use the four numbers as [w, x, y, z]
if (!JS_ValueToNumber(context, arrayW, &dVal)) return NO;
outQuaternion->w = dVal;
if (!JS_ValueToNumber(context, arrayX, &dVal)) return NO;
outQuaternion->x = dVal;
if (!JS_ValueToNumber(context, arrayY, &dVal)) return NO;
outQuaternion->y = dVal;
if (!JS_ValueToNumber(context, arrayZ, &dVal)) return NO;
outQuaternion->z = dVal;
return YES;
}
// ...se the four numbers as [w, x, y, z]
if (!JS_ValueToNumber(context, arrayW, &dVal)) return NO;
outQuaternion->w = dVal;
if (!JS_ValueToNumber(context, arrayX, &dVal)) return NO;
outQuaternion->x = dVal;
if (!JS_ValueToNumber(context, arrayY, &dVal)) return NO;
outQuaternion->y = dVal;
if (!JS_ValueToNumber(context, arrayZ, &dVal)) return NO;
outQuaternion->z = dVal;
return YES;
}
}
}

View File

@ -226,20 +226,14 @@ BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, Vector *outVecto
JS_LookupElement(context, vectorObj, 1, &arrayY) &&
JS_LookupElement(context, vectorObj, 2, &arrayZ))
{
// ...and all three elements are numbers...
if (JSVAL_IS_NUMBER(arrayX) &&
JSVAL_IS_NUMBER(arrayY) &&
JSVAL_IS_NUMBER(arrayZ))
{
// Use the three numbers as [x, y, z]
if (!JS_ValueToNumber(context, arrayX, &dVal)) return NO;
outVector->x = dVal;
if (!JS_ValueToNumber(context, arrayY, &dVal)) return NO;
outVector->y = dVal;
if (!JS_ValueToNumber(context, arrayZ, &dVal)) return NO;
outVector->z = dVal;
return YES;
}
// ...use the three numbers as [x, y, z]
if (!JS_ValueToNumber(context, arrayX, &dVal)) return NO;
outVector->x = dVal;
if (!JS_ValueToNumber(context, arrayY, &dVal)) return NO;
outVector->y = dVal;
if (!JS_ValueToNumber(context, arrayZ, &dVal)) return NO;
outVector->z = dVal;
return YES;
}
}
}