Oolite
Loading...
Searching...
No Matches
OOJSVector.h
Go to the documentation of this file.
1/*
2
3OOJSVector.h
4
5JavaScript proxy for vectors.
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
27#import "OOMaths.h"
28#import <Foundation/Foundation.h>
29#include <jsapi.h>
30
31void InitOOJSVector(JSContext* context, JSObject* global);
32
33JSObject* JSVectorWithVector(JSContext* context, Vector vector) NONNULL_FUNC;
34JSObject* JSVectorWithHPVector(JSContext* context, HPVector vector) NONNULL_FUNC;
35
36BOOL VectorToJSValue(JSContext* context, Vector vector, jsval* outValue) NONNULL_FUNC;
37BOOL HPVectorToJSValue(JSContext* context, HPVector vector, jsval* outValue) NONNULL_FUNC;
38BOOL NSPointToVectorJSValue(JSContext* context, NSPoint point, jsval* outValue) NONNULL_FUNC;
39BOOL JSValueToVector(JSContext* context, jsval value, Vector* outVector) NONNULL_FUNC;
40BOOL JSValueToHPVector(JSContext* context, jsval value, HPVector* outVector) NONNULL_FUNC;
41
42/* Given a JS Vector object, get the corresponding Vector struct. Given a JS
43 Entity, get its position. Given a JS Array with exactly three elements,
44 all of them numbers, treat them as [x, y, z] components. For anything
45 else, return NO. (Other implicit conversions may be added in future.)
46*/
47BOOL JSObjectGetVector(JSContext* context, JSObject* vectorObj, HPVector* outVector) GCC_ATTR((nonnull(1, 3)));
48
49// Set the value of a JS vector object.
50BOOL JSVectorSetVector(JSContext* context, JSObject* vectorObj, Vector vector) GCC_ATTR((nonnull(1)));
51BOOL JSVectorSetHPVector(JSContext* context, JSObject* vectorObj, HPVector vector) GCC_ATTR((nonnull(1)));
52
53/* VectorFromArgumentList()
54
55 Construct a vector from an argument list which is either a (JS) vector, a
56 (JS) entity, or an array of three numbers. The optional outConsumed
57 argument can be used to find out how many parameters were used
58 (currently, this will be 0 on failure, otherwise 1).
59
60 On failure, it will return NO and raise an error. If the caller is a JS
61 callback, it must return NO to signal an error.
62
63 DEPRECATED in favour of JSObjectGetVector(), since the list-of-number form
64 is no longer used.
65*/
66BOOL VectorFromArgumentList(JSContext* context, NSString* scriptClass, NSString* function, uintN argc, jsval* argv, HPVector* outVector, uintN* outConsumed) GCC_ATTR((nonnull(1, 5, 6)));
67
68/* VectorFromArgumentListNoError()
69
70 Like VectorFromArgumentList(), but does not report an error on failure.
71*/
72BOOL VectorFromArgumentListNoError(JSContext* context, uintN argc, jsval* argv, HPVector* outVector, uintN* outConsumed) GCC_ATTR((nonnull(1, 3, 4)));
#define NONNULL_FUNC
#define GCC_ATTR(x)
JSObject * JSVectorWithHPVector(JSContext *context, HPVector vector) NONNULL_FUNC
Definition OOJSVector.m:282
JSObject * JSVectorWithVector(JSContext *context, Vector vector) NONNULL_FUNC
Definition OOJSVector.m:236
BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC
Definition OOJSVector.m:341
BOOL HPVectorToJSValue(JSContext *context, HPVector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:310
BOOL BOOL JSVectorSetVector(JSContext *context, JSObject *vectorObj, Vector vector) GCC_ATTR((nonnull(1)))
Definition OOJSVector.m:493
BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:328
BOOL JSValueToHPVector(JSContext *context, jsval value, HPVector *outVector) NONNULL_FUNC
Definition OOJSVector.m:333
void InitOOJSVector(JSContext *context, JSObject *global)
Definition OOJSVector.m:231
BOOL BOOL VectorFromArgumentListNoError(JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed) GCC_ATTR((nonnull(1
BOOL JSVectorSetHPVector(JSContext *context, JSObject *vectorObj, HPVector vector) GCC_ATTR((nonnull(1)))
Definition OOJSVector.m:498
BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC
Definition OOJSVector.m:264
BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector) GCC_ATTR((nonnull(1
BOOL VectorFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed) GCC_ATTR((nonnull(1