Oolite
Loading...
Searching...
No Matches
OOJSPlayerShip.h File Reference
import "PlayerEntity.h"
import <Foundation/Foundation.h>
#include <quickjs.h>
Include dependency graph for OOJSPlayerShip.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void InitOOJSPlayerShip (JSContext *context, JSValueConst global)
JSClassID JSPlayerShipClassID (void)
JSValue JSPlayerShipObject (void)

Function Documentation

◆ InitOOJSPlayerShip()

void InitOOJSPlayerShip ( JSContext * context,
JSValueConst global )

Definition at line 256 of file OOJSPlayerShip.m.

257{
259
260 JSValue shipPrototype = JS_GetClassProto(context, JSShipClassID());
261 NSCAssert(JS_IsObject(shipPrototype), @"Ship must be initialized before PlayerShip.");
262 OOJSInitClass(context, global, sPlayerShipClassID, shipPrototype, OOJSUnconstructableConstruct, 0,
264 JS_FreeValue(context, shipPrototype);
265
268
269 PlayerEntity* player = [PlayerEntity sharedPlayer]; // NOTE: at time of writing, this creates the player entity. Don't use PLAYER here.
270
271 // Create ship object as a property of the player object.
272 JSValue playerObject = JS_GetPropertyStr(context, global, "player");
273 NSCAssert(JS_IsObject(playerObject), @"Player must be initialized before PlayerShip.");
274
275 JSValue shipObject = JS_NewObjectClass(context, (int)sPlayerShipClassID);
276 JS_SetOpaque(shipObject, OOConsumeReference([player weakRetain]));
277 // The player object's property and the player entity each own a reference.
278 JS_DefinePropertyValueStr(context, playerObject, "ship", JS_DupValue(context, shipObject), OOJS_PROP_READONLY);
279 [player setJSSelf:shipObject context:context];
280
281 JS_FreeValue(context, shipObject);
282 JS_FreeValue(context, playerObject);
283 // Analyzer: object leaked. [Expected, object is retained by JS object.]
284}
id OOConsumeReference(id OO_NS_CONSUMED value)
static JSFunctionSpec sPlayerShipMethods[]
static JSClass sPlayerShipClass
static JSPropertySpec sPlayerShipProperties[]
void OOJSRegisterObjectConverter(JSClass *theClass, OOJSClassConverterCallback converter)
JSBool OOJSUnconstructableConstruct(JSContext *context, uintN argc, jsval *vp)
#define OOJS_PROP_READONLY
void OOJSRegisterSubclass(JSClass *subclass, JSClass *superclass)
id OOJSBasicPrivateObjectConverter(JSContext *context, JSObject *object)
static JSClassID sPlayerShipClassID
JSClassID JSShipClassID(void)
Definition OOJSShip.m:576
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 JSShipClassID(), OOConsumeReference(), OOJS_COUNT, OOJS_PROP_READONLY, OOJSBasicPrivateObjectConverter(), OOJSInitClass(), OOJSRegisterClass(), OOJSRegisterObjectConverter(), OOJSRegisterSubclass(), OOJSUnconstructableConstruct(), PlayerEntity::setJSSelf:context:, PlayerEntity::sharedPlayer, sPlayerShipClass, sPlayerShipClassID, sPlayerShipMethods, and sPlayerShipProperties.

Here is the call graph for this function:

◆ JSPlayerShipClassID()

JSClassID JSPlayerShipClassID ( void )

Definition at line 286 of file OOJSPlayerShip.m.

287{
288 return sPlayerShipClassID;
289}

References sPlayerShipClassID.

◆ JSPlayerShipObject()

JSValue JSPlayerShipObject ( void )

Definition at line 294 of file OOJSPlayerShip.m.

295{
296 return sPlayerShipObject;
297}
static JSObject * sPlayerShipObject

References JSPlayerObject(), OOJSAcquireContext(), and OOJSRelinquishContext().

Here is the call graph for this function: