Line data Source code
1 0 : /*
2 :
3 : OOJSVector.h
4 :
5 : JavaScript proxy for vectors.
6 :
7 : Oolite
8 : Copyright (C) 2004-2013 Giles C Williams and contributors
9 :
10 : This program is free software; you can redistribute it and/or
11 : modify it under the terms of the GNU General Public License
12 : as published by the Free Software Foundation; either version 2
13 : of the License, or (at your option) any later version.
14 :
15 : This program is distributed in the hope that it will be useful,
16 : but WITHOUT ANY WARRANTY; without even the implied warranty of
17 : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 : GNU General Public License for more details.
19 :
20 : You should have received a copy of the GNU General Public License
21 : along with this program; if not, write to the Free Software
22 : Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
23 : MA 02110-1301, USA.
24 :
25 : */
26 :
27 : #import <Foundation/Foundation.h>
28 : #include <jsapi.h>
29 : #import "OOMaths.h"
30 :
31 :
32 0 : void InitOOJSVector(JSContext *context, JSObject *global);
33 :
34 :
35 0 : JSObject *JSVectorWithVector(JSContext *context, Vector vector) NONNULL_FUNC;
36 0 : JSObject *JSVectorWithHPVector(JSContext *context, HPVector vector) NONNULL_FUNC;
37 :
38 0 : BOOL VectorToJSValue(JSContext *context, Vector vector, jsval *outValue) NONNULL_FUNC;
39 0 : BOOL HPVectorToJSValue(JSContext *context, HPVector vector, jsval *outValue) NONNULL_FUNC;
40 0 : BOOL NSPointToVectorJSValue(JSContext *context, NSPoint point, jsval *outValue) NONNULL_FUNC;
41 0 : BOOL JSValueToVector(JSContext *context, jsval value, Vector *outVector) NONNULL_FUNC;
42 0 : BOOL 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 : */
49 0 : BOOL JSObjectGetVector(JSContext *context, JSObject *vectorObj, HPVector *outVector) GCC_ATTR((nonnull (1, 3)));
50 :
51 : // Set the value of a JS vector object.
52 0 : BOOL JSVectorSetVector(JSContext *context, JSObject *vectorObj, Vector vector) GCC_ATTR((nonnull (1)));
53 0 : BOOL 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 : */
69 0 : BOOL 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 : */
75 0 : BOOL VectorFromArgumentListNoError(JSContext *context, uintN argc, jsval *argv, HPVector *outVector, uintN *outConsumed) GCC_ATTR((nonnull (1, 3, 4)));
76 :
77 :
78 :
|