forked from AtomicGameEngine/AtomicGameEngine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJSAPI.h
More file actions
executable file
·75 lines (57 loc) · 3.26 KB
/
JSAPI.h
File metadata and controls
executable file
·75 lines (57 loc) · 3.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//
// Copyright (c) 2014-2015, THUNDERBEAST GAMES LLC All rights reserved
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
#pragma once
#include <Duktape/duktape.h>
typedef void* JS_HEAP_PTR;
#include "../Javascript/JSVM.h"
#define JS_GLOBALSTASH_INDEX_REFCOUNTED_REGISTRY 0
#define JS_GLOBALSTASH_VARIANTMAP_CACHE 1
// indexers for instance objects
#define JS_INSTANCE_INDEX_FINALIZED 0
namespace Atomic
{
class JSVM;
class Object;
void js_class_declare_internal(JSVM* vm, void* uniqueClassID, const char* package, const char* classname, duk_c_function constructor);
template<typename T>
void js_class_declare(JSVM* vm, const char* package, const char* classname, duk_c_function constructor)
{
js_class_declare_internal(vm, (void*) T::GetClassIDStatic(), package, classname, constructor);
}
void js_constructor_basecall(duk_context* ctx, const char* package, const char* baseclass);
void js_setup_prototype(JSVM* vm, const char* package, const char* classname, const char* basePackage, const char* basename, bool hasProperties = false);
void js_class_push_propertyobject(JSVM* vm, const char* package, const char* classname);
void js_class_get_prototype(duk_context* ctx, const char* package, const char *classname);
void js_class_get_constructor(duk_context* ctx, const char* package, const char *classname);
// setup a native event wrapper on module object at the top of the stack
void js_define_native_event(duk_context* ctx, const String& eventType, const String& eventName);
/// Pushes variant value or undefined if can't be pushed
void js_push_variant(duk_context* ctx, const Variant &v, int arrayIndex = -1);
void js_push_variantmap(duk_context* ctx, const VariantMap &vmap);
// Get a default value for the given variant type and set variantOut
void js_get_default_variant(VariantType variantType, Variant& variantOut);
/// Sets a variant value from the duktape stack
void js_to_variant(duk_context* ctx, int variantIdx, Variant &v, VariantType variantType = VAR_NONE);
void js_object_to_variantmap(duk_context* ctx, int objIdx, VariantMap &v);
/// Returns true if the item is a buffer, and if data and size are passed, they are given values to access the buffer data.
duk_bool_t js_check_is_buffer_and_get_data(duk_context* ctx, duk_idx_t idx, void** data, duk_size_t* size);
}