forked from godotjs/javascript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathecmascript_binding_helper.h
66 lines (50 loc) · 2.03 KB
/
ecmascript_binding_helper.h
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
#ifndef ECMASCRIPT_BINDING_HELPER_H
#define ECMASCRIPT_BINDING_HELPER_H
#include "core/object.h"
#include "core/reference.h"
#define PROTOTYPE_LITERAL "prototype"
#define PROTO_LITERAL "__proto__"
#define ECMA_CLASS_NAME_LITERAL "class_name"
struct ECMAScriptGCHandler {
void *ecma_object;
bool is_null() const { return ecma_object == NULL; }
};
struct ECMAScriptBindingData : public ECMAScriptGCHandler {
Object *godot_object;
ObjectID instance_id;
};
typedef ECMAScriptGCHandler ECMAMethodInfo;
struct ECMAProperyInfo {
Variant::Type type;
Variant default_value;
};
struct ECMAClassInfo {
ECMAScriptGCHandler ecma_constructor;
StringName class_name;
String icon_path;
bool tool;
ClassDB::ClassInfo *native_class;
HashMap<StringName, ECMAMethodInfo> methods;
HashMap<StringName, MethodInfo> signals;
HashMap<StringName, ECMAProperyInfo> properties;
};
class ECMAScriptBindingHelper {
friend class ECMAScript;
protected:
HashMap<StringName, ECMAClassInfo> ecma_classes;
public:
virtual void clear_classes() { ecma_classes.clear(); }
virtual void initialize() = 0;
virtual void uninitialize() = 0;
virtual void *alloc_object_binding_data(Object *p_object) = 0;
virtual void free_object_binding_data(void *p_gc_handle) = 0;
virtual void godot_refcount_incremented(Reference *p_object) = 0;
virtual bool godot_refcount_decremented(Reference *p_object) = 0;
virtual Error eval_string(const String &p_source) = 0;
virtual Error safe_eval_text(const String &p_source, String &r_error) = 0;
virtual ECMAScriptGCHandler create_ecma_instance_for_godot_object(const StringName &ecma_class_name, Object *p_object) = 0;
virtual Variant call_method(const ECMAScriptGCHandler &p_object, const ECMAMethodInfo &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) = 0;
virtual bool get_instance_property(const ECMAScriptGCHandler &p_object, const StringName &p_name, Variant &r_ret) = 0;
virtual bool set_instance_property(const ECMAScriptGCHandler &p_object, const StringName &p_name, const Variant &p_value) = 0;
};
#endif