Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOJSOolite.m File Reference
+ Include dependency graph for OOJSOolite.m:

Go to the source code of this file.

Enumerations

enum  {
  kOolite_version , kOolite_versionString , kOolite_jsVersion , kOolite_jsVersionString ,
  kOolite_gameSettings , kOolite_resourcePaths
}
 

Functions

static JSBool OoliteGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static NSString * VersionString (void)
 
static NSArray * VersionComponents (void)
 
static JSBool OoliteCompareVersion (JSContext *context, uintN argc, jsval *vp)
 
void InitOOJSOolite (JSContext *context, JSObject *global)
 

Variables

static JSClass sOoliteClass
 
static JSPropertySpec sOoliteProperties []
 
static JSFunctionSpec sOoliteMethods []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kOolite_version 
kOolite_versionString 
kOolite_jsVersion 
kOolite_jsVersionString 
kOolite_gameSettings 
kOolite_resourcePaths 

Definition at line 59 of file OOJSOolite.m.

60{
61 // Property IDs
62 kOolite_version, // version number components, array, read-only
63 kOolite_versionString, // version number as string, string, read-only
64 kOolite_jsVersion, // JavaScript version, integer, read-only
65 kOolite_jsVersionString, // JavaScript version as string, string, read-only
66 kOolite_gameSettings, // Various game settings, object, read-only
67 kOolite_resourcePaths, // Paths containing resources, built-in plus oxp/oxz, read-only
68};
@ kOolite_version
Definition OOJSOolite.m:62
@ kOolite_jsVersionString
Definition OOJSOolite.m:65
@ kOolite_jsVersion
Definition OOJSOolite.m:64
@ kOolite_gameSettings
Definition OOJSOolite.m:66
@ kOolite_resourcePaths
Definition OOJSOolite.m:67
@ kOolite_versionString
Definition OOJSOolite.m:63

Function Documentation

◆ InitOOJSOolite()

void InitOOJSOolite ( JSContext * context,
JSObject * global )

Definition at line 92 of file OOJSOolite.m.

93{
94 JSObject *oolitePrototype = JS_InitClass(context, global, NULL, &sOoliteClass, OOJSUnconstructableConstruct, 0, sOoliteProperties, sOoliteMethods, NULL, NULL);
95 JS_DefineObject(context, global, "oolite", &sOoliteClass, oolitePrototype, OOJS_PROP_READONLY);
96}
static JSFunctionSpec sOoliteMethods[]
Definition OOJSOolite.m:84
static JSPropertySpec sOoliteProperties[]
Definition OOJSOolite.m:71
static JSClass sOoliteClass
Definition OOJSOolite.m:43
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY

References OOJS_PROP_READONLY, OOJSUnconstructableConstruct(), sOoliteClass, sOoliteMethods, and sOoliteProperties.

+ Here is the call graph for this function:

◆ OoliteCompareVersion()

static JSBool OoliteCompareVersion ( JSContext * context,
uintN argc,
jsval * vp )
static

Definition at line 164 of file OOJSOolite.m.

165{
166 OOJS_NATIVE_ENTER(context)
167
168 id components = nil;
169 NSEnumerator *componentEnum = nil;
170 id component = nil;
171
172 if (argc == 0) OOJS_RETURN_VOID; // Backwards-compatibility: be overly lenient.
173
174 components = OOJSNativeObjectFromJSValue(context, OOJS_ARGV[0]);
175 if ([components isKindOfClass:[NSArray class]])
176 {
177 // Require each element to be a number
178 for (componentEnum = [components objectEnumerator]; (component = [componentEnum nextObject]); )
179 {
180 if (![component isKindOfClass:[NSNumber class]])
181 {
182 components = nil;
183 break;
184 }
185 }
186 }
187 else if ([components isKindOfClass:[NSString class]])
188 {
189 components = ComponentsFromVersionString(components);
190 }
191 else components = nil;
192
193 if (components != nil)
194 {
195 OOJS_RETURN_INT((int32_t)CompareVersions(components, VersionComponents()));
196 }
197 else
198 {
200 }
201
203}
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
static NSArray * VersionComponents(void)
Definition OOJSOolite.m:151
id OOJSNativeObjectFromJSValue(JSContext *context, jsval value)
#define OOJS_ARGV
#define OOJS_RETURN_VOID
#define OOJS_RETURN_INT(v)
return nil
NSArray * ComponentsFromVersionString(NSString *string)
NSComparisonResult CompareVersions(NSArray *version1, NSArray *version2)

References CompareVersions(), ComponentsFromVersionString(), nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_INT, OOJS_RETURN_VOID, OOJSNativeObjectFromJSValue(), and VersionComponents().

+ Here is the call graph for this function:

◆ OoliteGetProperty()

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

Definition at line 99 of file OOJSOolite.m.

100{
101 if (!JSID_IS_INT(propID)) return YES;
102
103 OOJS_NATIVE_ENTER(context)
104
105 id result = nil;
106
107 switch (JSID_TO_INT(propID))
108 {
109 case kOolite_version:
110 result = VersionComponents();
111 break;
112
114 result = VersionString();
115 break;
116
118 *value = INT_TO_JSVAL(JS_GetVersion(context));
119 return YES;
120
122 *value = STRING_TO_JSVAL(JS_NewStringCopyZ(context, JS_VersionToString(JS_GetVersion(context))));
123 return YES;
124
126 result = [UNIVERSE gameSettings];
127 break;
128
130 result = [ResourceManager paths];
131 break;
132
133 default:
134 OOJSReportBadPropertySelector(context, this, propID, sOoliteProperties);
135 return NO;
136 }
137
138 *value = OOJSValueFromNativeObject(context, result);
139 return YES;
140
142}
static NSString * VersionString(void)
Definition OOJSOolite.m:145
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)

References kOolite_gameSettings, kOolite_jsVersion, kOolite_jsVersionString, kOolite_resourcePaths, kOolite_version, kOolite_versionString, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromNativeObject(), ResourceManager::paths, sOoliteProperties, VersionComponents(), and VersionString().

+ Here is the call graph for this function:

◆ VersionComponents()

static NSArray * VersionComponents ( void )
static

Definition at line 151 of file OOJSOolite.m.

152{
154}

References ComponentsFromVersionString(), and VersionString().

Referenced by OoliteCompareVersion(), and OoliteGetProperty().

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

◆ VersionString()

static NSString * VersionString ( void )
static

Definition at line 145 of file OOJSOolite.m.

146{
147 return [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
148}

Referenced by OoliteGetProperty(), and VersionComponents().

+ Here is the caller graph for this function:

Variable Documentation

◆ sOoliteClass

JSClass sOoliteClass
static
Initial value:
=
{
"Oolite",
0,
JS_PropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JS_FinalizeStub
}
static JSBool OoliteGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSOolite.m:99

Definition at line 43 of file OOJSOolite.m.

44{
45 "Oolite",
46 0,
47
48 JS_PropertyStub,
49 JS_PropertyStub,
51 JS_StrictPropertyStub,
52 JS_EnumerateStub,
53 JS_ResolveStub,
54 JS_ConvertStub,
55 JS_FinalizeStub
56};

Referenced by InitOOJSOolite().

◆ sOoliteMethods

JSFunctionSpec sOoliteMethods[]
static
Initial value:
=
{
{ "compareVersion", OoliteCompareVersion, 1 },
{ 0 }
}
static JSBool OoliteCompareVersion(JSContext *context, uintN argc, jsval *vp)
Definition OOJSOolite.m:164

Definition at line 84 of file OOJSOolite.m.

85{
86 // JS name Function min args
87 { "compareVersion", OoliteCompareVersion, 1 },
88 { 0 }
89};

Referenced by InitOOJSOolite().

◆ sOoliteProperties

JSPropertySpec sOoliteProperties[]
static
Initial value:
=
{
{ 0 }
}
#define OOJS_PROP_READONLY_CB

Definition at line 71 of file OOJSOolite.m.

72{
73 // JS name ID flags
76 { "jsVersionString", kOolite_jsVersionString, OOJS_PROP_READONLY_CB },
78 { "versionString", kOolite_versionString, OOJS_PROP_READONLY_CB },
79 { "resourcePaths", kOolite_resourcePaths, OOJS_PROP_READONLY_CB },
80 { 0 }
81};

Referenced by InitOOJSOolite(), and OoliteGetProperty().