Work on JavaScript API update.

git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@3854 127b21dd-08f5-0310-b4b7-95ae10353056
This commit is contained in:
Jens Ayton 2010-12-15 23:33:21 +00:00
parent 295c921403
commit 233a0c76c1
5 changed files with 40 additions and 52 deletions

View File

@ -193,10 +193,7 @@ static JSBool ClockGetProperty(OOJS_PROP_ARGS)
static JSBool JSClockToString(OOJS_NATIVE_ARGS)
{
OOJS_NATIVE_ENTER(context)
*outResult = [[OOPlayerForScripting() dial_clock] javaScriptValueInContext:context];
return YES;
OOJS_RETURN_OBJECT([OOPlayerForScripting() dial_clock]);
OOJS_NATIVE_EXIT
}
@ -208,11 +205,9 @@ static JSBool ClockClockStringForTime(OOJS_NATIVE_ARGS)
double time;
if (EXPECT_NOT(!JS_ValueToNumber(context, argv[0], &time))) return NO;
*outResult = [ClockToString(time, NO) javaScriptValueInContext:context];
return YES;
if (EXPECT_NOT(!JS_ValueToNumber(context, OOJS_ARG(0), &time))) return NO;
OOJS_RETURN_OBJECT(ClockToString(time, NO));
OOJS_NATIVE_EXIT
}
@ -224,19 +219,16 @@ static JSBool ClockAddSeconds(OOJS_NATIVE_ARGS)
double time;
if (EXPECT_NOT(!JS_ValueToNumber(context, argv[0], &time))) return YES; // no-op
if (EXPECT_NOT(!JS_ValueToNumber(context, OOJS_ARG(0), &time))) return NO;
if (time > 2592000.0f || time < 1.0f) // 30 * 24 * 3600
{
OOReportJSWarning(context, @"Clock.addSeconds: use a value between 1 and 2592000 (30 days).");
*outResult = JSVAL_FALSE;
return YES;
OOJS_RETURN_BOOL(NO);
}
[OOPlayerForScripting() addToAdjustTime:time];
*outResult = JSVAL_TRUE;
return YES;
OOJS_RETURN_BOOL(YES);
OOJS_NATIVE_EXIT
}

View File

@ -33,9 +33,9 @@ static JSObject *sEquipmentInfoPrototype;
static JSBool EquipmentInfoGetProperty(OOJS_PROP_ARGS);
static JSBool EquipmentInfoSetProperty(JSContext *context, JSObject *this, jsval name, jsval *outValue);
static JSBool EquipmentInfoSetProperty(OOJS_PROP_ARGS);
static JSBool EquipmentInfoGetAllEqipment(JSContext *context, JSObject *this, jsval name, jsval *outValue);
static JSBool EquipmentInfoGetAllEqipment(OOJS_PROP_ARGS);
// Methods
@ -384,11 +384,11 @@ static JSBool EquipmentInfoSetProperty(OOJS_PROP_ARGS)
}
static JSBool EquipmentInfoGetAllEqipment(JSContext *context, JSObject *this, jsval name, jsval *outValue)
static JSBool EquipmentInfoGetAllEqipment(OOJS_PROP_ARGS)
{
OOJS_NATIVE_ENTER(context)
*outValue = [[OOEquipmentType allEquipmentTypes] javaScriptValueInContext:context];
*value = [[OOEquipmentType allEquipmentTypes] javaScriptValueInContext:context];
return YES;
OOJS_NATIVE_EXIT
@ -435,16 +435,14 @@ static JSBool EquipmentInfoStaticInfoForKey(OOJS_NATIVE_ARGS)
NSString *key = nil;
key = JSValToNSString(context, argv[0]);
key = JSValToNSString(context, OOJS_ARG(0));
if (key == nil)
{
OOReportJSBadArguments(context, @"EquipmentInfo", @"infoForKey", argc, argv, nil, @"string");
OOReportJSBadArguments(context, @"EquipmentInfo", @"infoForKey", argc, OOJS_ARGV, nil, @"string");
return NO;
}
*outResult = [[OOEquipmentType equipmentTypeWithIdentifier:key] javaScriptValueInContext:context];
return YES;
OOJS_RETURN_OBJECT([OOEquipmentType equipmentTypeWithIdentifier:key]);
OOJS_NATIVE_EXIT
}

View File

@ -512,14 +512,14 @@ static JSBool PlayerShipUseSpecialCargo(OOJS_NATIVE_ARGS)
PlayerEntity *player = OOPlayerShipForScripting();
NSString *name = nil;
name = JSValToNSString(context, argv[0]);
name = JSValToNSString(context, OOJS_ARG(0));
if (EXPECT_NOT(name == nil))
{
OOReportJSBadArguments(context, @"PlayerShip", @"useSpecialCargo", argc, argv, nil, @"special cargo description");
OOReportJSBadArguments(context, @"PlayerShip", @"useSpecialCargo", argc, OOJS_ARGV, nil, @"special cargo description");
return NO;
}
[player useSpecialCargo:JSValToNSString(context, argv[0])];
[player useSpecialCargo:JSValToNSString(context, OOJS_ARG(0))];
return YES;
OOJS_NATIVE_EXIT
@ -531,21 +531,19 @@ static JSBool PlayerShipEngageAutopilotToStation(OOJS_NATIVE_ARGS)
{
OOJS_NATIVE_ENTER(context)
if (EXPECT_NOT([UNIVERSE blockJSPlayerShipProps])) return YES;
if (EXPECT_NOT([UNIVERSE blockJSPlayerShipProps])) return YES;
PlayerEntity *player = OOPlayerShipForScripting();
StationEntity *stationForDocking = nil;
stationForDocking = JSValueToObjectOfClass(context, argv[0], [StationEntity class]);
stationForDocking = JSValueToObjectOfClass(context, OOJS_ARG(0), [StationEntity class]);
if (stationForDocking == nil)
{
OOReportJSBadArguments(context, @"PlayerShip", @"engageAutopilot", argc, argv, nil, @"station for docking");
OOReportJSBadArguments(context, @"PlayerShip", @"engageAutopilot", argc, OOJS_ARGV, nil, @"station for docking");
return NO;
}
*outResult = BOOLToJSVal([player engageAutopilotToStation:stationForDocking]);
return YES;
OOJS_RETURN_BOOL([player engageAutopilotToStation:stationForDocking]);
OOJS_NATIVE_EXIT
}
@ -578,23 +576,21 @@ static JSBool PlayerShipAwardEquipmentToCurrentPylon(OOJS_NATIVE_ARGS)
NSString *key = nil;
OOEquipmentType *eqType = nil;
key = JSValueToEquipmentKey(context, argv[0]);
key = JSValueToEquipmentKey(context, OOJS_ARG(0));
if (EXPECT_NOT(key == nil))
{
OOReportJSBadArguments(context, @"PlayerShip", @"awardEquipmentToCurrentPylon", argc, argv, nil, @"equipment type");
OOReportJSBadArguments(context, @"PlayerShip", @"awardEquipmentToCurrentPylon", argc, OOJS_ARGV, nil, @"equipment type");
return NO;
}
eqType = [OOEquipmentType equipmentTypeWithIdentifier:key];
if (EXPECT_NOT(![eqType isMissileOrMine]))
{
OOReportJSBadArguments(context, @"PlayerShip", @"awardEquipmentToCurrentPylon", argc, argv, nil, @"external store");
OOReportJSBadArguments(context, @"PlayerShip", @"awardEquipmentToCurrentPylon", argc, OOJS_ARGV, nil, @"external store");
return NO;
}
*outResult = BOOLToJSVal([player assignToActivePylon:key]);
return YES;
OOJS_RETURN_BOOL([player assignToActivePylon:key]);
OOJS_NATIVE_EXIT
}

View File

@ -178,17 +178,19 @@ static JSBool SoundStaticLoad(OOJS_NATIVE_ARGS)
NSString *name = nil;
OOSound *sound = nil;
name = JSValToNSString(context, argv[0]);
name = JSValToNSString(context, OOJS_ARG(0));
if (name == nil)
{
OOReportJSBadArguments(context, @"Sound", @"load", argc, argv, nil, @"string");
OOReportJSBadArguments(context, @"Sound", @"load", argc, OOJS_ARGV, nil, @"string");
return NO;
}
OOJSPauseTimeLimiter();
sound = GetNamedSound(name);
*outResult = [sound javaScriptValueInContext:context];
if (*outResult == JSVAL_VOID) *outResult = JSVAL_NULL; // No sound by that name
if (sound != nil) OOJS_SET_RVAL([sound javaScriptValueInContext:context]);
else OOJS_SET_RVAL(JSVAL_VOID); // No sound by that name
OOJSResumeTimeLimiter();
return YES;
@ -205,17 +207,17 @@ static JSBool SoundStaticPlayMusic(OOJS_NATIVE_ARGS)
NSString *name = nil;
JSBool loop = NO;
name = JSValToNSString(context, argv[0]);
name = JSValToNSString(context, OOJS_ARG(0));
if (name == nil)
{
OOReportJSBadArguments(context, @"Sound", @"playMusic", 1, &argv[0], nil, @"string");
OOReportJSBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV, nil, @"string");
return NO;
}
if (argc >= 2)
{
if (!JS_ValueToBoolean(context, argv[1], &loop))
if (!JS_ValueToBoolean(context, OOJS_ARG(1), &loop))
{
OOReportJSBadArguments(context, @"Sound", @"playMusic", 1, &argv[1], nil, @"boolean");
OOReportJSBadArguments(context, @"Sound", @"playMusic", 1, OOJS_ARGV + 1, nil, @"boolean");
return NO;
}
}
@ -239,10 +241,10 @@ static JSBool SoundStaticStopMusic(OOJS_NATIVE_ARGS)
OOJSPauseTimeLimiter();
if (argc > 0)
{
name = JSValToNSString(context, argv[0]);
name = JSValToNSString(context, OOJS_ARG(0));
if (name == nil)
{
OOReportJSBadArguments(context, @"Sound", @"stopMusic", argc, argv, nil, @"string or no argument");
OOReportJSBadArguments(context, @"Sound", @"stopMusic", argc, OOJS_ARGV, nil, @"string or no argument");
return NO;
}
[[OOMusicController sharedController] stopMusicNamed:name];

View File

@ -163,8 +163,8 @@ static JSBool SunGoNova(OOJS_NATIVE_ARGS)
OOSunEntity *sun = nil;
jsdouble delay = 0;
if (EXPECT_NOT(!JSSunGetSunEntity(context, this, &sun))) return NO;
if (argc > 0 && EXPECT_NOT(!JS_ValueToNumber(context, argv[0], &delay))) return NO;
if (EXPECT_NOT(!JSSunGetSunEntity(context, OOJS_THIS, &sun))) return NO;
if (argc > 0 && EXPECT_NOT(!JS_ValueToNumber(context, OOJS_ARG(0), &delay))) return NO;
[sun setGoingNova:YES inTime:delay];
return YES;
@ -180,7 +180,7 @@ static JSBool SunCancelNova(OOJS_NATIVE_ARGS)
OOSunEntity *sun = nil;
if (EXPECT_NOT(!JSSunGetSunEntity(context, this, &sun))) return NO;
if (EXPECT_NOT(!JSSunGetSunEntity(context, OOJS_THIS, &sun))) return NO;
if ([sun willGoNova] && ![sun goneNova])
{