Oolite
Loading...
Searching...
No Matches
OOJSQuaternion.h
Go to the documentation of this file.
1/*
2
3OOJSQuaternion.h (QuickJS-ng proof of concept)
4
5JavaScript proxy for quaternions.
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 <quickjs.h>
30
31void InitOOJSQuaternion(JSContext* context, JSValueConst global);
32
33// Return an owned Quaternion object, or JS_EXCEPTION.
34JSValue JSQuaternionWithQuaternion(JSContext* context, Quaternion quaternion) NONNULL_FUNC;
35
36// *outValue is owned by the caller on success.
37BOOL QuaternionToJSValue(JSContext* context, Quaternion quaternion, JSValue* outValue) NONNULL_FUNC;
38BOOL JSValueToQuaternion(JSContext* context, JSValueConst value, Quaternion* outQuaternion) NONNULL_FUNC;
39
40/* Given a JS Quaternion object, get the corresponding Vector struct. Given a
41 JS Entity, get its orientation. Given a JS Array with exactly four
42 elements, all of them numbers, treat them as [w, x, y, z] components. For
43 anything else, return NO. (Other implicit conversions may be added in
44 future.)
45*/
46BOOL JSObjectGetQuaternion(JSContext* context, JSValueConst quaternionObj, Quaternion* outQuaternion) GCC_ATTR((nonnull(1, 3)));
47
48// Set the value of a JS quaternion object.
49BOOL JSQuaternionSetQuaternion(JSContext* context, JSValueConst quaternionObj, Quaternion quaternion) GCC_ATTR((nonnull(1)));
50
51/* QuaternionFromArgumentList()
52
53 Construct a quaternion from an argument list which is either a (JS)
54 quaternion, a (JS) entity, four numbers or a JS array of four numbers. The
55 optional outConsumed argument can be used to find out how many parameters
56 were used (currently, this will be 0 on failure, otherwise 1 or 4).
57
58 On failure, it will return NO and raise an error. If the caller is a JS
59 callback, it must return JS_EXCEPTION to signal an error.
60*/
61BOOL QuaternionFromArgumentList(JSContext* context, NSString* scriptClass, NSString* function, int argc, JSValueConst* argv, Quaternion* outQuaternion, int* outConsumed) GCC_ATTR((nonnull(1, 6)));
62
63/* QuaternionFromArgumentList()
64
65 Like VectorFromArgumentList(), but does not report an error on failure.
66*/
67BOOL QuaternionFromArgumentListNoError(JSContext* context, int argc, JSValueConst* argv, Quaternion* outVector, int* outConsumed) GCC_ATTR((nonnull(1, 4)));
#define NONNULL_FUNC
#define GCC_ATTR(x)
BOOL BOOL JSQuaternionSetQuaternion(JSContext *context, JSObject *quaternionObj, Quaternion quaternion) GCC_ATTR((nonnull(1)))
BOOL QuaternionFromArgumentList(JSContext *context, NSString *scriptClass, NSString *function, uintN argc, jsval *argv, Quaternion *outQuaternion, uintN *outConsumed) GCC_ATTR((nonnull(1
void InitOOJSQuaternion(JSContext *context, JSObject *global)
BOOL BOOL QuaternionFromArgumentListNoError(JSContext *context, uintN argc, jsval *argv, Quaternion *outVector, uintN *outConsumed) GCC_ATTR((nonnull(1
BOOL JSObjectGetQuaternion(JSContext *context, JSObject *quaternionObj, Quaternion *outQuaternion) GCC_ATTR((nonnull(1
BOOL JSValueToQuaternion(JSContext *context, jsval value, Quaternion *outQuaternion) NONNULL_FUNC
JSObject * JSQuaternionWithQuaternion(JSContext *context, Quaternion quaternion) NONNULL_FUNC
BOOL QuaternionToJSValue(JSContext *context, Quaternion quaternion, jsval *outValue) NONNULL_FUNC