40@implementation Entity (OOJavaScriptExtensions)
54- (jsval) oo_jsValueInContext:(JSContext *)context
56 JSClass *
class = NULL;
57 JSObject *prototype = NULL;
58 jsval result = JSVAL_NULL;
63 [
self getJSClass:&class andPrototype:&prototype];
65 _jsSelf = JS_NewObject(context,
class, prototype, NULL);
68 if (!JS_SetPrivate(context, _jsSelf,
OOConsumeReference([
self weakRetain]))) _jsSelf = NULL;
74 [[NSNotificationCenter defaultCenter] addObserver:self
75 selector:@selector(deleteJSSelf)
76 name:kOOJavaScriptEngineWillResetNotification
81 if (_jsSelf != NULL) result = OBJECT_TO_JSVAL(_jsSelf);
88- (void) getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
101 JS_RemoveObjectRoot(context, &_jsSelf);
104 [[NSNotificationCenter defaultCenter] removeObserver:self
105 name:kOOJavaScriptEngineWillResetNotification
113@implementation ShipEntity (OOJavaScriptExtensions)
115- (BOOL) isVisibleToScripts
121- (void) getJSClass:(JSClass **)outClass andPrototype:(JSObject **)outPrototype
128- (NSString *) oo_jsClassName
134- (NSArray *) subEntitiesForScript
136 return [[
self shipSubEntityEnumerator] allObjects];
140- (void) setTargetForScript:(
ShipEntity *)target
145 while ([me isSubEntity])
147 if (me == [me owner] || [me owner] ==
nil)
break;
150 while ([target isSubEntity])
152 if (target == [target owner] || [target owner] ==
nil)
break;
155 if (![me isKindOfClass:[
ShipEntity class]])
return;
id OOConsumeReference(id OO_NS_CONSUMED value)
OOINLINE JSClass * JSEntityClass(void)
OOINLINE JSObject * JSEntityPrototype(void)
JSObject * JSShipPrototype(void)
JSClass * JSShipClass(void)
OOINLINE JSContext * OOJSAcquireContext(void)
#define OOJSAddGCObjectRoot(context, root, name)
OOINLINE void OOJSRelinquishContext(JSContext *context)
BOOL isVisibleToScripts()
NSString * oo_jsClassName()
OOJavaScriptEngine * sharedEngine()
void addTarget:(Entity *targetEntity)
void removeTarget:(Entity *targetEntity)