37 NSCParameterAssert(JSID_IS_STRING(propID));
40 if ([key hasPrefix:
@"_"])
return nil;
41 return [@"mission_" stringByAppendingString:key];
48static JSBool
MissionVariablesEnumerate(JSContext *context, JSObject *
object, JSIterateOp enumOp, jsval *state, jsid *idp);
58 JSCLASS_NEW_ENUMERATE,
85 return [PLAYER missionVariables];
96 if (JSID_IS_STRING(propID))
113 if (JSID_IS_STRING(propID))
116 if (key ==
nil)
return YES;
120 if ([mvar isKindOfClass:[NSString
class]])
124 return JS_NewNumberValue(context, [mvar doubleValue], value);
142 if (JSID_IS_STRING(propID))
153 if ([objValue isKindOfClass:[NSNull
class]]) objValue =
nil;
166 NSEnumerator *enumerator =
nil;
170 case JSENUMERATE_INIT:
171 case JSENUMERATE_INIT_ALL:
174 NSArray *mvars = [[PLAYER missionVariables] allKeys];
175 enumerator = [[mvars objectEnumerator] retain];
176 *state = PRIVATE_TO_JSVAL(enumerator);
178 NSUInteger
count = [mvars count];
179 assert(
count <= INT32_MAX);
180 if (idp != NULL) *idp = INT_TO_JSID((uint32_t)
count);
184 case JSENUMERATE_NEXT:
186 enumerator = JSVAL_TO_PRIVATE(*state);
189 NSString *next = [enumerator nextObject];
190 if (next ==
nil)
break;
191 if (![next hasPrefix:
@"mission_"])
continue;
193 next = [next substringFromIndex:8];
195 jsval val = [next oo_jsValueInContext:context];
196 return JS_ValueToId(context, val, idp);
204 case JSENUMERATE_DESTROY:
206 if (enumerator ==
nil && JSVAL_IS_DOUBLE(*state))
208 enumerator = JSVAL_TO_PRIVATE(*state);
210 [enumerator release];
212 if (idp != NULL) *idp = JSID_VOID;
BOOL OOIsNumberLiteral(NSString *string, BOOL allowSpaces)
#define OOJS_NATIVE_ENTER(cx)
void InitOOJSMissionVariables(JSContext *context, JSObject *global)
static NSString * KeyForPropertyID(JSContext *context, jsid propID)
static JSBool MissionVariablesGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool MissionVariablesSetProperty(JSContext *context, JSObject *this, jsid propID, JSBool strict, jsval *value)
static JSBool MissionVariablesEnumerate(JSContext *context, JSObject *object, JSIterateOp enumOp, jsval *state, jsid *idp)
static id MissionVariablesConverter(JSContext *context, JSObject *object)
static JSBool MissionVariablesDeleteProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSClass sMissionVariablesClass
PlayerEntity * OOPlayerForScripting(void)
NSString * OOStringFromJSID(jsid propID)
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
NSString * OOStringFromJSValue(JSContext *context, jsval value)
#define OOJS_PROP_READONLY
void OOJSReportError(JSContext *context, NSString *format,...)
NSString * OOStringFromJSString(JSContext *context, JSString *string)
NSString * missionVariableForKey:(NSString *key)
void setMissionVariable:forKey:(NSString *value,[forKey] NSString *key)