Oolite
Loading...
Searching...
No Matches
OOJSWorldScripts.m File Reference
Include dependency graph for OOJSWorldScripts.m:

Go to the source code of this file.

Functions

static JSBool WorldScriptsGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
static JSBool WorldScriptsEnumerate (JSContext *cx, JSObject *obj)
void InitOOJSWorldScripts (JSContext *context, JSObject *global)

Variables

static JSClass sWorldScriptsClass

Function Documentation

◆ InitOOJSWorldScripts()

void InitOOJSWorldScripts ( JSContext * context,
JSObject * global )

Definition at line 48 of file OOJSWorldScripts.m.

49{
50 JS_DefineObject(context, global, "worldScripts", &sWorldScriptsClass, NULL, OOJS_PROP_READONLY);
51}
static JSClass sWorldScriptsClass
#define OOJS_PROP_READONLY

References OOJS_PROP_READONLY, and sWorldScriptsClass.

Referenced by OOJavaScriptEngine(Private)::createMainThreadContext.

Here is the caller graph for this function:

◆ WorldScriptsEnumerate()

JSBool WorldScriptsEnumerate ( JSContext * cx,
JSObject * obj )
static

Definition at line 84 of file OOJSWorldScripts.m.

85{
86 OOJS_NATIVE_ENTER(context)
87
88 /* In order to support enumeration of world scripts (e.g.,
89 for (name in worldScripts) { ... }), define each property on demand.
90 Since world scripts cannot be deleted, we don't need to worry about
91 that case (as in OOJSMissionVariables).
92
93 Since WorldScriptsGetProperty() will be called for each access anyway,
94 we define the value as null here.
95 */
96
97 NSArray* names = nil;
98 NSString* name = nil;
99
101
102 foreach (name, names) {
103 if (!JS_DefineProperty(context, object, [name UTF8String], JSVAL_NULL, WorldScriptsGetProperty, NULL, OOJS_PROP_READONLY_CB))
104 return NO;
105 }
106
107 return YES;
108
110}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
static JSBool WorldScriptsGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
#define OOJS_PROP_READONLY_CB
return nil
NSArray * worldScriptNames()

References nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_PROP_READONLY_CB, PlayerEntity::worldScriptNames, and WorldScriptsGetProperty().

Here is the call graph for this function:

◆ WorldScriptsGetProperty()

JSBool WorldScriptsGetProperty ( JSContext * context,
JSObject * this,
jsid propID,
jsval * value )
static

Definition at line 53 of file OOJSWorldScripts.m.

54{
55 OOJS_NATIVE_ENTER(context)
56
58 NSString* scriptName = nil;
59 id script = nil;
60
61 if (!JSID_IS_STRING(propID))
62 return YES;
63 scriptName = OOStringFromJSString(context, JSID_TO_STRING(propID));
64
65 if (scriptName != nil) {
66 script = [[player worldScriptsByName] objectForKey:scriptName];
67 if (script != nil) {
68 /* If script is an OOJSScript, this should return a JS Script
69 object. For other OOScript subclasses, it will return
70 JSVAL_NULL. If no script exists, the value will be
71 JSVAL_VOID.
72 */
73 *value = [script oo_jsValueInContext:context];
74 } else {
75 *value = JSVAL_VOID;
76 }
77 }
78
79 return YES;
80
82}
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:175
NSString * OOStringFromJSString(JSContext *context, JSString *string)
NSDictionary * worldScriptsByName()

References nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOPlayerForScripting(), OOStringFromJSString(), and PlayerEntity::worldScriptsByName.

Referenced by WorldScriptsEnumerate().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ sWorldScriptsClass

JSClass sWorldScriptsClass
static
Initial value:
= {
"WorldScripts",
0,
JS_PropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub
}
static JSBool WorldScriptsEnumerate(JSContext *cx, JSObject *obj)

Definition at line 34 of file OOJSWorldScripts.m.

34 {
35 "WorldScripts",
36 0,
37
38 JS_PropertyStub,
39 JS_PropertyStub,
41 JS_StrictPropertyStub,
43 JS_ResolveStub,
44 JS_ConvertStub,
45 JS_FinalizeStub
46};

Referenced by InitOOJSWorldScripts(), and InitOOJSWorldScripts().