Oolite
Loading...
Searching...
No Matches
OOJSSun.m File Reference
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 JSValue SunGetProperty (OOJS_GETTER_ARGS)
static JSValue SunGoNova (OOJS_NATIVE_ARGS)
static JSValue SunCancelNova (OOJS_NATIVE_ARGS)
void InitOOJSSun (JSContext *context, JSValueConst global)
JSClassID JSSunClassID (void)

Variables

static JSClassID sSunClassID
static JSClassDef sSunClass
static const JSCFunctionListEntry sSunProperties []
static const JSCFunctionListEntry sSunMethods []

Enumeration Type Documentation

◆ anonymous enum

anonymous enum
Enumerator
kSun_radius 
kSun_hasGoneNova 
kSun_isGoingNova 
kSun_name 

Definition at line 43 of file OOJSSun.m.

43 {
44 // Property IDs
45 kSun_radius, // Radius of sun in metres, number, read-only
46 kSun_hasGoneNova, // Has sun gone nova, boolean, read-only
47 kSun_isGoingNova, // Will sun go nova, boolean, read-only
48 kSun_name // Name of sun, string, read-only (writable via systeminfo)
49};
@ kSun_name
Definition OOJSSun.m:58
@ kSun_radius
Definition OOJSSun.m:55
@ kSun_hasGoneNova
Definition OOJSSun.m:56
@ kSun_isGoingNova
Definition OOJSSun.m:57

Function Documentation

◆ InitOOJSSun()

void InitOOJSSun ( JSContext * context,
JSValueConst global )

Definition at line 67 of file OOJSSun.m.

68{
70
71 JSValue parentPrototype = JS_GetClassProto(context, JSEntityClassID());
72 NSCAssert(JS_IsObject(parentPrototype), @"Entity must be initialized before Sun.");
73 OOJSInitClass(context, global, sSunClassID, parentPrototype, OOJSUnconstructableConstruct, 0,
75 JS_FreeValue(context, parentPrototype);
76
79}
static JSClass sSunClass
Definition OOJSSun.m:38
static JSFunctionSpec sSunMethods[]
Definition OOJSSun.m:70
static JSPropertySpec sSunProperties[]
Definition OOJSSun.m:61
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)
JSClassID JSEntityClassID(void)
Definition OOJSEntity.m:115
static JSClassID sSunClassID
Definition OOJSSun.m:32
JSClassID OOJSRegisterClass(JSClassID *ioClassID, const JSClassDef *classDef)
Definition OOJSClasses.m:61
JSValueConst OOJSInitClass(JSContext *context, JSValueConst global, JSClassID classID, JSValueConst parentPrototype, JSCFunction *constructor, int constructorArgCount, const JSCFunctionListEntry *properties, size_t propertyCount, const JSCFunctionListEntry *methods, size_t methodCount, const JSCFunctionListEntry *staticMethods, size_t staticMethodCount)
#define OOJS_COUNT(array)

References InitOOJSSun(), JSEntityClassID(), OOJS_COUNT, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), sSunClass, sSunClassID, sSunMethods, and sSunProperties.

Here is the call graph for this function:

◆ JSSunClassID()

JSClassID JSSunClassID ( void )

Definition at line 81 of file OOJSSun.m.

82{
83 return sSunClassID;
84}

References sSunClassID.

◆ SunCancelNova()

JSValue SunCancelNova ( OOJS_NATIVE_ARGS )
static

Definition at line 157 of file OOJSSun.m.

158{
159 OOJS_NATIVE_ENTER(context)
160
161 OOSunEntity* sun = nil;
162
163 if (EXPECT_NOT(!JSSunGetSunEntity(context, OOJS_THIS, &sun)))
164 return OOJSNativeFailure(context);
165
166 if ([sun willGoNova] && ![sun goneNova]) {
167 [sun setGoingNova:NO inTime:0];
168 }
170
172}
#define EXPECT_NOT(x)
#define OOJS_NATIVE_ENTER(cx)
#define OOJS_NATIVE_EXIT
#define OOJS_THIS
#define OOJS_RETURN_VOID
return nil
JSValue OOJSNativeFailure(JSContext *context)
void setGoingNova:inTime:(BOOL yesno,[inTime] double interval)

References EXPECT_NOT, nil, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSNativeFailure(), and OOSunEntity::setGoingNova:inTime:.

Here is the call graph for this function:

◆ SunGetProperty()

JSValue SunGetProperty ( OOJS_GETTER_ARGS )
static

Definition at line 105 of file OOJSSun.m.

106{
107 OOJS_NATIVE_ENTER(context)
108
109 OOSunEntity* sun = nil;
110
111 if (EXPECT_NOT(!JSSunGetSunEntity(context, this, &sun)))
112 return OOJSNativeFailure(context);
113
114 switch (magic) {
115 case kSun_radius:
116 return JS_NewNumber(context, [sun radius]);
117
118 case kSun_name:
119 return OOJSValueFromNativeObject(context, [sun name]);
120
121 case kSun_hasGoneNova:
122 return OOJSValueFromBOOL([sun goneNova]);
123
124 case kSun_isGoingNova:
125 return OOJSValueFromBOOL([sun willGoNova] && ![sun goneNova]);
126
127 default:
129 return OOJSNativeFailure(context);
130 }
131
133}
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_COUNT, OOJS_GETTER_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJSNativeFailure(), OOJSReportBadPropertySelector(), OOJSValueFromBOOL(), OOJSValueFromNativeObject(), and sSunProperties.

Here is the call graph for this function:

◆ SunGoNova()

JSValue SunGoNova ( OOJS_NATIVE_ARGS )
static

Definition at line 138 of file OOJSSun.m.

139{
140 OOJS_NATIVE_ENTER(context)
141
142 OOSunEntity* sun = nil;
143 double delay = 0;
144
145 if (EXPECT_NOT(!JSSunGetSunEntity(context, OOJS_THIS, &sun)))
146 return OOJSNativeFailure(context);
147 if (argc > 0 && EXPECT_NOT(JS_ToFloat64(context, &delay, OOJS_ARGV[0]) != 0))
148 return OOJSNativeFailure(context);
149
150 [sun setGoingNova:YES inTime:delay];
152
154}
#define OOJS_ARGV

References EXPECT_NOT, nil, OOJS_ARGV, OOJS_NATIVE_ARGS, OOJS_NATIVE_ENTER, OOJS_NATIVE_EXIT, OOJS_RETURN_VOID, OOJS_THIS, OOJSNativeFailure(), and OOSunEntity::setGoingNova:inTime:.

Here is the call graph for this function:

Variable Documentation

◆ sSunClass

JSClassDef sSunClass
static
Initial value:
= {
.class_name = "Sun",
}
void OOJSObjectWrapperFinalize(JSContext *context, JSObject *this)

Definition at line 38 of file OOJSSun.m.

38 {
39 .class_name = "Sun",
40 .finalizer = OOJSObjectWrapperFinalize,
41};

◆ sSunClassID

JSClassID sSunClassID
static

◆ sSunMethods

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

Definition at line 59 of file OOJSSun.m.

59 {
60 // JS name, min args, function
61 JS_CFUNC_DEF("cancelNova", 0, SunCancelNova),
62 JS_CFUNC_DEF("goNova", 1, SunGoNova),
63};

◆ sSunProperties

const JSCFunctionListEntry sSunProperties[]
static
Initial value:
= {
}
static JSBool SunGetProperty(JSContext *context, JSObject *this, jsid propID, jsval *value)
Definition OOJSSun.m:106
#define OOJS_PROPERTY_RO(name, getter, magic)

Definition at line 51 of file OOJSSun.m.

51 {
52 // JS name, getter, setter, ID
57};