Oolite
Loading...
Searching...
No Matches
OOJSEntity.h
Go to the documentation of this file.
1/*
2
3OOJSEntity.h
4
5JavaScript proxy for entities.
6
7Oolite
8Copyright (C) 2004-2013 Giles C Williams and contributors
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18GNU General Public License for more details.
19
20You should have received a copy of the GNU General Public License
21along with this program; if not, write to the Free Software
22Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23MA 02110-1301, USA.
24
25*/
26
29#import "Universe.h"
30#import <Foundation/Foundation.h>
31
32@class Entity;
33
34void InitOOJSEntity(JSContext* context, JSObject* global);
35
36BOOL JSValueToEntity(JSContext* context, jsval value, Entity** outEntity);
37
38extern JSClass gOOEntityJSClass;
39extern JSObject* gOOEntityJSPrototype;
41
42OOINLINE JSClass* JSEntityClass(void) { return &gOOEntityJSClass; }
44
45/* EntityFromArgumentList()
46
47 Construct a entity from an argument list containing a JS Entity object.
48 The optional outConsumed argument can be used to find out how many
49 parameters were used (currently, this will be 0 on failure, otherwise 1).
50
51 On failure, it will return NO, annd the entity will be unaltered. If
52 scriptClass and function are non-nil, a warning will be reported to the
53 log.
54*/
55BOOL EntityFromArgumentList(JSContext* context, NSString* scriptClass, NSString* function, uintN argc, jsval* argv, Entity** outEntity, uintN* outConsumed);
56
57/*
58 For scripting purposes, a JS entity object is a stale reference if its
59 underlying ObjC object is nil, or if it refers to the player and the
60 blockJSPlayerShipProps flag is in effect (i.e., the escape pod sequence is
61 active).
62*/
64{
66 return gOOJSPlayerIfStale != nil;
67}
68
70{
72 return entity == nil || (entity == gOOJSPlayerIfStale);
73}
#define OOINLINE
OOINLINE BOOL OOIsPlayerStale(void)
Definition OOJSEntity.h:63
JSClass gOOEntityJSClass
Definition OOJSEntity.m:44
BOOL JSValueToEntity(JSContext *context, jsval value, Entity **outEntity)
Definition OOJSEntity.m:133
BOOL EntityFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, Entity **outEntity, uintN *outConsumed)
Definition OOJSEntity.m:142
JSObject * gOOEntityJSPrototype
Definition OOJSEntity.m:36
OOINLINE BOOL OOIsStaleEntity(Entity *entity)
Definition OOJSEntity.h:69
void InitOOJSEntity(JSContext *context, JSObject *global)
Definition OOJSEntity.m:127
OOINLINE JSClass * JSEntityClass(void)
Definition OOJSEntity.h:42
OOINLINE JSObject * JSEntityPrototype(void)
Definition OOJSEntity.h:43
#define DEFINE_JS_OBJECT_GETTER(NAME, JSCLASS, JSPROTO, OBJCCLASSNAME)
return nil
Entity * gOOJSPlayerIfStale
Definition Universe.m:134