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