Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/object/script_instance.h
9903 views
1
/**************************************************************************/
2
/* script_instance.h */
3
/**************************************************************************/
4
/* This file is part of: */
5
/* GODOT ENGINE */
6
/* https://godotengine.org */
7
/**************************************************************************/
8
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
9
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
10
/* */
11
/* Permission is hereby granted, free of charge, to any person obtaining */
12
/* a copy of this software and associated documentation files (the */
13
/* "Software"), to deal in the Software without restriction, including */
14
/* without limitation the rights to use, copy, modify, merge, publish, */
15
/* distribute, sublicense, and/or sell copies of the Software, and to */
16
/* permit persons to whom the Software is furnished to do so, subject to */
17
/* the following conditions: */
18
/* */
19
/* The above copyright notice and this permission notice shall be */
20
/* included in all copies or substantial portions of the Software. */
21
/* */
22
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
23
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
24
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
25
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
26
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
27
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
28
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
29
/**************************************************************************/
30
31
#pragma once
32
33
#include "core/object/ref_counted.h"
34
35
class Script;
36
class ScriptLanguage;
37
38
class ScriptInstance {
39
public:
40
virtual bool set(const StringName &p_name, const Variant &p_value) = 0;
41
virtual bool get(const StringName &p_name, Variant &r_ret) const = 0;
42
virtual void get_property_list(List<PropertyInfo> *p_properties) const = 0;
43
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const = 0;
44
virtual void validate_property(PropertyInfo &p_property) const = 0;
45
46
virtual bool property_can_revert(const StringName &p_name) const = 0;
47
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const = 0;
48
49
virtual Object *get_owner() { return nullptr; }
50
virtual void get_property_state(List<Pair<StringName, Variant>> &state);
51
52
virtual void get_method_list(List<MethodInfo> *p_list) const = 0;
53
virtual bool has_method(const StringName &p_method) const = 0;
54
55
virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const;
56
57
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) = 0;
58
59
template <typename... VarArgs>
60
Variant call(const StringName &p_method, VarArgs... p_args) {
61
Variant args[sizeof...(p_args) + 1] = { p_args..., Variant() }; // +1 makes sure zero sized arrays are also supported.
62
const Variant *argptrs[sizeof...(p_args) + 1];
63
for (uint32_t i = 0; i < sizeof...(p_args); i++) {
64
argptrs[i] = &args[i];
65
}
66
Callable::CallError cerr;
67
return callp(p_method, sizeof...(p_args) == 0 ? nullptr : (const Variant **)argptrs, sizeof...(p_args), cerr);
68
}
69
70
virtual Variant call_const(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); // implement if language supports const functions
71
virtual void notification(int p_notification, bool p_reversed = false) = 0;
72
virtual String to_string(bool *r_valid) {
73
if (r_valid) {
74
*r_valid = false;
75
}
76
return String();
77
}
78
79
//this is used by script languages that keep a reference counter of their own
80
//you can make Ref<> not die when it reaches zero, so deleting the reference
81
//depends entirely from the script
82
83
virtual void refcount_incremented() {}
84
virtual bool refcount_decremented() { return true; } //return true if it can die
85
86
virtual Ref<Script> get_script() const = 0;
87
88
virtual bool is_placeholder() const { return false; }
89
90
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid);
91
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid);
92
93
virtual const Variant get_rpc_config() const;
94
95
virtual ScriptLanguage *get_language() = 0;
96
virtual ~ScriptInstance();
97
};
98
99