Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
OOJSSun.m File Reference
import "OOJSSun.h"
import "OOJSEntity.h"
import "OOJavaScriptEngine.h"
import "OOSunEntity.h"
+ Include dependency graph for OOJSSun.m:

Go to the source code of this file.

Enumerations

enum  { kSun_radius , kSun_hasGoneNova , kSun_isGoingNova , kSun_name }
 

Functions

static JSBool SunGetProperty (JSContext *context, JSObject *this, jsid propID, jsval *value)
 
static JSBool SunGoNova (JSContext *context, uintN argc, jsval *vp)
 
static JSBool SunCancelNova (JSContext *context, uintN argc, jsval *vp)
 
void InitOOJSSun (JSContext *context, JSObject *global)
 

Variables

static JSObject * sSunPrototype
 
static JSClass sSunClass
 
static JSPropertySpec sSunProperties []
 
static JSFunctionSpec sSunMethods []
 

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSun_radius 
kSun_hasGoneNova 
kSun_isGoingNova 
kSun_name 

Definition at line 58 of file OOJSSun.m.

59{
60 // Property IDs
61 kSun_radius, // Radius of sun in metres, number, read-only
62 kSun_hasGoneNova, // Has sun gone nova, boolean, read-only
63 kSun_isGoingNova, // Will sun go nova, boolean, read-only
64 kSun_name // Name of sun, string, read-only (writable via systeminfo)
65};
@ kSun_name
Definition OOJSSun.m:64
@ kSun_radius
Definition OOJSSun.m:61
@ kSun_hasGoneNova
Definition OOJSSun.m:62
@ kSun_isGoingNova
Definition OOJSSun.m:63

Function Documentation

◆ InitOOJSSun()

void InitOOJSSun ( JSContext * context,
JSObject * global )

Definition at line 91 of file OOJSSun.m.

92{
93 sSunPrototype = JS_InitClass(context, global, JSEntityPrototype(), &sSunClass, OOJSUnconstructableConstruct, 0, sSunProperties, sSunMethods, NULL, NULL);
96}
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
OOINLINE JSObject * JSEntityPrototype(void)
Definition OOJSEntity.h:43
static JSClass sSunClass
Definition OOJSSun.m:41
static JSObject * sSunPrototype
Definition OOJSSun.m:33
static JSFunctionSpec sSunMethods[]
Definition OOJSSun.m:79
static JSPropertySpec sSunProperties[]
Definition OOJSSun.m:68
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)

References JSEntityClass(), JSEntityPrototype(), OOJSBasicPrivateObjectConverter(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sSunClass, sSunMethods, sSunProperties, and sSunPrototype.

+ Here is the call graph for this function:

◆ SunCancelNova()

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

Definition at line 179 of file OOJSSun.m.

180{
181 OOJS_NATIVE_ENTER(context)
182
183 OOSunEntity *sun = nil;
184
185 if (EXPECT_NOT(!JSSunGetSunEntity(context, OOJS_THIS, &sun))) return NO;
186
187 if ([sun willGoNova] && ![sun goneNova])
188 {
189 [sun setGoingNova:NO inTime:0];
190 }
192
194}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_THIS
#define OOJS_RETURN_VOID
return nil
void setGoingNova:inTime:(BOOL yesno,[inTime] double interval)

◆ SunGetProperty()

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

Definition at line 122 of file OOJSSun.m.

123{
124 if (!JSID_IS_INT(propID)) return YES;
125
126 OOJS_NATIVE_ENTER(context)
127
128 OOSunEntity *sun = nil;
129
130 if (EXPECT_NOT(!JSSunGetSunEntity(context, this, &sun))) return NO;
131
132 switch (JSID_TO_INT(propID))
133 {
134 case kSun_radius:
135 return JS_NewNumberValue(context, [sun radius], value);
136
137 case kSun_name:
138 *value = OOJSValueFromNativeObject(context, [sun name]);
139 return YES;
140
141 case kSun_hasGoneNova:
142 *value = OOJSValueFromBOOL([sun goneNova]);
143 return YES;
144
145 case kSun_isGoingNova:
146 *value = OOJSValueFromBOOL([sun willGoNova] && ![sun goneNova]);
147 return YES;
148
149 default:
150 OOJSReportBadPropertySelector(context, this, propID, sSunProperties);
151 return NO;
152 }
153
155}
OOINLINE jsval OOJSValueFromNativeObject(JSContext *context, id object)
void OOJSReportBadPropertySelector(JSContext *context, JSObject *thisObj, jsid propID, JSPropertySpec *propertySpec)
OOINLINE jsval OOJSValueFromBOOL(int b) INLINE_CONST_FUNC

References EXPECT_NOT, kSun_hasGoneNova, kSun_isGoingNova, kSun_name, kSun_radius, nil, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), and sSunProperties.

+ Here is the call graph for this function:

◆ SunGoNova()

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

Definition at line 161 of file OOJSSun.m.

162{
163 OOJS_NATIVE_ENTER(context)
164
165 OOSunEntity *sun = nil;
166 jsdouble delay = 0;
167
168 if (EXPECT_NOT(!JSSunGetSunEntity(context, OOJS_THIS, &sun))) return NO;
169 if (argc > 0 && EXPECT_NOT(!JS_ValueToNumber(context, OOJS_ARGV[0], &delay))) return NO;
170
171 [sun setGoingNova:YES inTime:delay];
173
175}
#define OOJS_ARGV

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, and OOSunEntity::setGoingNova:inTime:.

+ Here is the call graph for this function:

Variable Documentation

◆ sSunClass

JSClass sSunClass
static
Initial value:
=
{
"Sun",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
JSCLASS_NO_OPTIONAL_MEMBERS
}
static JSBool SunGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSSun.m:122
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 41 of file OOJSSun.m.

42{
43 "Sun",
44 JSCLASS_HAS_PRIVATE,
45
46 JS_PropertyStub, // addProperty
47 JS_PropertyStub, // delProperty
48 SunGetProperty, // getProperty
49 JS_StrictPropertyStub, // setProperty
50 JS_EnumerateStub, // enumerate
51 JS_ResolveStub, // resolve
52 JS_ConvertStub, // convert
54 JSCLASS_NO_OPTIONAL_MEMBERS
55};

Referenced by InitOOJSSun().

◆ sSunMethods

JSFunctionSpec sSunMethods[]
static
Initial value:
=
{
{ "cancelNova", SunCancelNova, 0 },
{ "goNova", SunGoNova, 1 },
{ 0 }
}
static JSBool SunCancelNova(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSun.m:179
static JSBool SunGoNova(JSContext *context, uintN argc, jsval *vp)
Definition OOJSSun.m:161

Definition at line 79 of file OOJSSun.m.

80{
81 // JS name Function min args
82 { "cancelNova", SunCancelNova, 0 },
83 { "goNova", SunGoNova, 1 },
84 { 0 }
85};

Referenced by InitOOJSSun().

◆ sSunProperties

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

Definition at line 68 of file OOJSSun.m.

69{
70 // JS name ID flags
71 { "hasGoneNova", kSun_hasGoneNova, OOJS_PROP_READONLY_CB },
72 { "isGoingNova", kSun_isGoingNova, OOJS_PROP_READONLY_CB },
75 { 0 }
76};

Referenced by InitOOJSSun(), and SunGetProperty().

◆ sSunPrototype

JSObject* sSunPrototype
static

Definition at line 33 of file OOJSSun.m.

Referenced by InitOOJSSun().