Oolite 1.91.0.7604-240417-a536cbe
Loading...
Searching...
No Matches
Functions | Variables
OOJSWorldScripts.m File Reference
import "OOJSWorldScripts.h"
import "OOJavaScriptEngine.h"
import "PlayerEntity.h"
import "OOJSPlayer.h"
+ 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 52 of file OOJSWorldScripts.m.

53{
54 JS_DefineObject(context, global, "worldScripts", &sWorldScriptsClass, NULL, OOJS_PROP_READONLY);
55}
static JSClass sWorldScriptsClass
#define OOJS_PROP_READONLY

References OOJS_PROP_READONLY, and sWorldScriptsClass.

◆ WorldScriptsEnumerate()

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

Definition at line 94 of file OOJSWorldScripts.m.

95{
96 OOJS_NATIVE_ENTER(context)
97
98 /* In order to support enumeration of world scripts (e.g.,
99 for (name in worldScripts) { ... }), define each property on demand.
100 Since world scripts cannot be deleted, we don't need to worry about
101 that case (as in OOJSMissionVariables).
102
103 Since WorldScriptsGetProperty() will be called for each access anyway,
104 we define the value as null here.
105 */
106
107 NSArray *names = nil;
108 NSEnumerator *nameEnum = nil;
109 NSString *name = nil;
110
111 names = [OOPlayerForScripting() worldScriptNames];
112
113 for (nameEnum = [names objectEnumerator]; (name = [nameEnum nextObject]); )
114 {
115 if (!JS_DefineProperty(context, object, [name UTF8String], JSVAL_NULL, WorldScriptsGetProperty, NULL, OOJS_PROP_READONLY_CB)) return NO;
116 }
117
118 return YES;
119
121}
#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

References nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_PROP_READONLY_CB, and WorldScriptsGetProperty().

+ Here is the call graph for this function:

◆ WorldScriptsGetProperty()

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

Definition at line 58 of file OOJSWorldScripts.m.

59{
60 OOJS_NATIVE_ENTER(context)
61
63 NSString *scriptName = nil;
64 id script = nil;
65
66 if (!JSID_IS_STRING(propID)) return YES;
67 scriptName = OOStringFromJSString(context, JSID_TO_STRING(propID));
68
69 if (scriptName != nil)
70 {
71 script = [[player worldScriptsByName] objectForKey:scriptName];
72 if (script != nil)
73 {
74 /* If script is an OOJSScript, this should return a JS Script
75 object. For other OOScript subclasses, it will return
76 JSVAL_NULL. If no script exists, the value will be
77 JSVAL_VOID.
78 */
79 *value = [script oo_jsValueInContext:context];
80 }
81 else
82 {
83 *value = JSVAL_VOID;
84 }
85
86 }
87
88 return YES;
89
91}
PlayerEntity * OOPlayerForScripting(void)
Definition OOJSPlayer.m:191
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 36 of file OOJSWorldScripts.m.

37{
38 "WorldScripts",
39 0,
40
41 JS_PropertyStub,
42 JS_PropertyStub,
44 JS_StrictPropertyStub,
46 JS_ResolveStub,
47 JS_ConvertStub,
48 JS_FinalizeStub
49};

Referenced by InitOOJSWorldScripts().