Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/core/object/script_language_extension.h
9903 views
1
/**************************************************************************/
2
/* script_language_extension.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/extension/ext_wrappers.gen.inc"
34
#include "core/object/gdvirtual.gen.inc"
35
#include "core/object/script_language.h"
36
#include "core/variant/native_ptr.h"
37
#include "core/variant/typed_array.h"
38
39
class ScriptExtension : public Script {
40
GDCLASS(ScriptExtension, Script)
41
42
protected:
43
EXBIND0R(bool, editor_can_reload_from_file)
44
45
GDVIRTUAL1(_placeholder_erased, GDExtensionPtr<void>)
46
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override {
47
GDVIRTUAL_CALL(_placeholder_erased, p_placeholder);
48
}
49
50
static void _bind_methods();
51
52
public:
53
EXBIND0RC(bool, can_instantiate)
54
EXBIND0RC(Ref<Script>, get_base_script)
55
EXBIND0RC(StringName, get_global_name)
56
EXBIND1RC(bool, inherits_script, const Ref<Script> &)
57
EXBIND0RC(StringName, get_instance_base_type)
58
59
GDVIRTUAL1RC_REQUIRED(GDExtensionPtr<void>, _instance_create, Object *)
60
virtual ScriptInstance *instance_create(Object *p_this) override {
61
GDExtensionPtr<void> ret = nullptr;
62
GDVIRTUAL_CALL(_instance_create, p_this, ret);
63
return reinterpret_cast<ScriptInstance *>(ret.operator void *());
64
}
65
GDVIRTUAL1RC_REQUIRED(GDExtensionPtr<void>, _placeholder_instance_create, Object *)
66
PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override {
67
GDExtensionPtr<void> ret = nullptr;
68
GDVIRTUAL_CALL(_placeholder_instance_create, p_this, ret);
69
return reinterpret_cast<PlaceHolderScriptInstance *>(ret.operator void *());
70
}
71
72
EXBIND1RC(bool, instance_has, const Object *)
73
EXBIND0RC(bool, has_source_code)
74
EXBIND0RC(String, get_source_code)
75
EXBIND1(set_source_code, const String &)
76
EXBIND1R(Error, reload, bool)
77
78
GDVIRTUAL0RC_REQUIRED(StringName, _get_doc_class_name)
79
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_documentation)
80
GDVIRTUAL0RC(String, _get_class_icon_path)
81
#ifdef TOOLS_ENABLED
82
virtual StringName get_doc_class_name() const override {
83
StringName ret;
84
GDVIRTUAL_CALL(_get_doc_class_name, ret);
85
return ret;
86
}
87
88
virtual Vector<DocData::ClassDoc> get_documentation() const override {
89
TypedArray<Dictionary> doc;
90
GDVIRTUAL_CALL(_get_documentation, doc);
91
92
Vector<DocData::ClassDoc> class_doc;
93
for (int i = 0; i < doc.size(); i++) {
94
class_doc.append(DocData::ClassDoc::from_dict(doc[i]));
95
}
96
97
return class_doc;
98
}
99
100
virtual String get_class_icon_path() const override {
101
String ret;
102
GDVIRTUAL_CALL(_get_class_icon_path, ret);
103
return ret;
104
}
105
#endif // TOOLS_ENABLED
106
107
EXBIND1RC(bool, has_method, const StringName &)
108
EXBIND1RC(bool, has_static_method, const StringName &)
109
110
GDVIRTUAL1RC(Variant, _get_script_method_argument_count, const StringName &)
111
virtual int get_script_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override {
112
Variant ret;
113
if (GDVIRTUAL_CALL(_get_script_method_argument_count, p_method, ret) && ret.get_type() == Variant::INT) {
114
if (r_is_valid) {
115
*r_is_valid = true;
116
}
117
return ret.operator int();
118
}
119
// Fallback to default.
120
return Script::get_script_method_argument_count(p_method, r_is_valid);
121
}
122
123
GDVIRTUAL1RC_REQUIRED(Dictionary, _get_method_info, const StringName &)
124
virtual MethodInfo get_method_info(const StringName &p_method) const override {
125
Dictionary mi;
126
GDVIRTUAL_CALL(_get_method_info, p_method, mi);
127
return MethodInfo::from_dict(mi);
128
}
129
130
EXBIND0RC(bool, is_tool)
131
EXBIND0RC(bool, is_valid)
132
133
virtual bool is_abstract() const override {
134
bool abst;
135
return GDVIRTUAL_CALL(_is_abstract, abst) && abst;
136
}
137
GDVIRTUAL0RC(bool, _is_abstract)
138
139
EXBIND0RC(ScriptLanguage *, get_language)
140
EXBIND1RC(bool, has_script_signal, const StringName &)
141
142
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_signal_list)
143
144
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override {
145
TypedArray<Dictionary> sl;
146
GDVIRTUAL_CALL(_get_script_signal_list, sl);
147
for (int i = 0; i < sl.size(); i++) {
148
r_signals->push_back(MethodInfo::from_dict(sl[i]));
149
}
150
}
151
152
GDVIRTUAL1RC_REQUIRED(bool, _has_property_default_value, const StringName &)
153
GDVIRTUAL1RC_REQUIRED(Variant, _get_property_default_value, const StringName &)
154
155
virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override {
156
bool has_dv = false;
157
if (!GDVIRTUAL_CALL(_has_property_default_value, p_property, has_dv) || !has_dv) {
158
return false;
159
}
160
Variant ret;
161
GDVIRTUAL_CALL(_get_property_default_value, p_property, ret);
162
r_value = ret;
163
return true;
164
}
165
166
EXBIND0(update_exports)
167
168
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_method_list)
169
170
virtual void get_script_method_list(List<MethodInfo> *r_methods) const override {
171
TypedArray<Dictionary> sl;
172
GDVIRTUAL_CALL(_get_script_method_list, sl);
173
for (int i = 0; i < sl.size(); i++) {
174
r_methods->push_back(MethodInfo::from_dict(sl[i]));
175
}
176
}
177
178
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_property_list)
179
180
virtual void get_script_property_list(List<PropertyInfo> *r_propertys) const override {
181
TypedArray<Dictionary> sl;
182
GDVIRTUAL_CALL(_get_script_property_list, sl);
183
for (int i = 0; i < sl.size(); i++) {
184
r_propertys->push_back(PropertyInfo::from_dict(sl[i]));
185
}
186
}
187
188
EXBIND1RC(int, get_member_line, const StringName &)
189
190
GDVIRTUAL0RC_REQUIRED(Dictionary, _get_constants)
191
192
virtual void get_constants(HashMap<StringName, Variant> *p_constants) override {
193
Dictionary constants;
194
GDVIRTUAL_CALL(_get_constants, constants);
195
for (const KeyValue<Variant, Variant> &kv : constants) {
196
p_constants->insert(kv.key, kv.value);
197
}
198
}
199
GDVIRTUAL0RC_REQUIRED(TypedArray<StringName>, _get_members)
200
virtual void get_members(HashSet<StringName> *p_members) override {
201
TypedArray<StringName> members;
202
GDVIRTUAL_CALL(_get_members, members);
203
for (int i = 0; i < members.size(); i++) {
204
p_members->insert(members[i]);
205
}
206
}
207
208
EXBIND0RC(bool, is_placeholder_fallback_enabled)
209
210
GDVIRTUAL0RC_REQUIRED(Variant, _get_rpc_config)
211
212
virtual const Variant get_rpc_config() const override {
213
Variant ret;
214
GDVIRTUAL_CALL(_get_rpc_config, ret);
215
return ret;
216
}
217
218
ScriptExtension() {}
219
};
220
221
typedef ScriptLanguage::ProfilingInfo ScriptLanguageExtensionProfilingInfo;
222
223
GDVIRTUAL_NATIVE_PTR(ScriptLanguageExtensionProfilingInfo)
224
225
class ScriptLanguageExtension : public ScriptLanguage {
226
GDCLASS(ScriptLanguageExtension, ScriptLanguage)
227
protected:
228
static void _bind_methods();
229
230
public:
231
EXBIND0RC(String, get_name)
232
233
EXBIND0(init)
234
EXBIND0RC(String, get_type)
235
EXBIND0RC(String, get_extension)
236
EXBIND0(finish)
237
238
/* EDITOR FUNCTIONS */
239
240
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_reserved_words)
241
242
virtual Vector<String> get_reserved_words() const override {
243
Vector<String> ret;
244
GDVIRTUAL_CALL(_get_reserved_words, ret);
245
return ret;
246
}
247
EXBIND1RC(bool, is_control_flow_keyword, const String &)
248
249
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_comment_delimiters)
250
251
virtual Vector<String> get_comment_delimiters() const override {
252
Vector<String> ret;
253
GDVIRTUAL_CALL(_get_comment_delimiters, ret);
254
return ret;
255
}
256
257
GDVIRTUAL0RC(Vector<String>, _get_doc_comment_delimiters)
258
259
virtual Vector<String> get_doc_comment_delimiters() const override {
260
Vector<String> ret;
261
GDVIRTUAL_CALL(_get_doc_comment_delimiters, ret);
262
return ret;
263
}
264
265
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_string_delimiters)
266
267
virtual Vector<String> get_string_delimiters() const override {
268
Vector<String> ret;
269
GDVIRTUAL_CALL(_get_string_delimiters, ret);
270
return ret;
271
}
272
273
EXBIND3RC(Ref<Script>, make_template, const String &, const String &, const String &)
274
275
GDVIRTUAL1RC_REQUIRED(TypedArray<Dictionary>, _get_built_in_templates, StringName)
276
277
virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override {
278
TypedArray<Dictionary> ret;
279
GDVIRTUAL_CALL(_get_built_in_templates, p_object, ret);
280
Vector<ScriptTemplate> stret;
281
for (int i = 0; i < ret.size(); i++) {
282
Dictionary d = ret[i];
283
ScriptTemplate st;
284
ERR_CONTINUE(!d.has("inherit"));
285
st.inherit = d["inherit"];
286
ERR_CONTINUE(!d.has("name"));
287
st.name = d["name"];
288
ERR_CONTINUE(!d.has("description"));
289
st.description = d["description"];
290
ERR_CONTINUE(!d.has("content"));
291
st.content = d["content"];
292
ERR_CONTINUE(!d.has("id"));
293
st.id = d["id"];
294
ERR_CONTINUE(!d.has("origin"));
295
st.origin = TemplateLocation(int(d["origin"]));
296
stret.push_back(st);
297
}
298
return stret;
299
}
300
301
EXBIND0R(bool, is_using_templates)
302
303
GDVIRTUAL6RC_REQUIRED(Dictionary, _validate, const String &, const String &, bool, bool, bool, bool)
304
virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override {
305
Dictionary ret;
306
GDVIRTUAL_CALL(_validate, p_script, p_path, r_functions != nullptr, r_errors != nullptr, r_warnings != nullptr, r_safe_lines != nullptr, ret);
307
if (!ret.has("valid")) {
308
return false;
309
}
310
if (r_functions != nullptr && ret.has("functions")) {
311
Vector<String> functions = ret["functions"];
312
for (int i = 0; i < functions.size(); i++) {
313
r_functions->push_back(functions[i]);
314
}
315
}
316
if (r_errors != nullptr && ret.has("errors")) {
317
Array errors = ret["errors"];
318
for (const Variant &error : errors) {
319
Dictionary err = error;
320
ERR_CONTINUE(!err.has("line"));
321
ERR_CONTINUE(!err.has("column"));
322
ERR_CONTINUE(!err.has("message"));
323
324
ScriptError serr;
325
if (err.has("path")) {
326
serr.path = err["path"];
327
}
328
serr.line = err["line"];
329
serr.column = err["column"];
330
serr.message = err["message"];
331
332
r_errors->push_back(serr);
333
}
334
}
335
if (r_warnings != nullptr && ret.has("warnings")) {
336
ERR_FAIL_COND_V(!ret.has("warnings"), false);
337
Array warnings = ret["warnings"];
338
for (const Variant &warning : warnings) {
339
Dictionary warn = warning;
340
ERR_CONTINUE(!warn.has("start_line"));
341
ERR_CONTINUE(!warn.has("end_line"));
342
ERR_CONTINUE(!warn.has("code"));
343
ERR_CONTINUE(!warn.has("string_code"));
344
ERR_CONTINUE(!warn.has("message"));
345
346
Warning swarn;
347
swarn.start_line = warn["start_line"];
348
swarn.end_line = warn["end_line"];
349
swarn.code = warn["code"];
350
swarn.string_code = warn["string_code"];
351
swarn.message = warn["message"];
352
353
r_warnings->push_back(swarn);
354
}
355
}
356
if (r_safe_lines != nullptr && ret.has("safe_lines")) {
357
PackedInt32Array safe_lines = ret["safe_lines"];
358
for (int i = 0; i < safe_lines.size(); i++) {
359
r_safe_lines->insert(safe_lines[i]);
360
}
361
}
362
return ret["valid"];
363
}
364
365
EXBIND1RC(String, validate_path, const String &)
366
GDVIRTUAL0RC_REQUIRED(Object *, _create_script)
367
Script *create_script() const override {
368
Object *ret = nullptr;
369
GDVIRTUAL_CALL(_create_script, ret);
370
return Object::cast_to<Script>(ret);
371
}
372
#ifndef DISABLE_DEPRECATED
373
EXBIND0RC(bool, has_named_classes)
374
#endif
375
EXBIND0RC(bool, supports_builtin_mode)
376
EXBIND0RC(bool, supports_documentation)
377
EXBIND0RC(bool, can_inherit_from_file)
378
379
EXBIND2RC(int, find_function, const String &, const String &)
380
EXBIND3RC(String, make_function, const String &, const String &, const PackedStringArray &)
381
EXBIND0RC(bool, can_make_function)
382
EXBIND3R(Error, open_in_external_editor, const Ref<Script> &, int, int)
383
EXBIND0R(bool, overrides_external_editor)
384
385
GDVIRTUAL0RC(ScriptNameCasing, _preferred_file_name_casing);
386
387
virtual ScriptNameCasing preferred_file_name_casing() const override {
388
ScriptNameCasing ret;
389
if (GDVIRTUAL_CALL(_preferred_file_name_casing, ret)) {
390
return ret;
391
}
392
return ScriptNameCasing::SCRIPT_NAME_CASING_SNAKE_CASE;
393
}
394
395
GDVIRTUAL3RC_REQUIRED(Dictionary, _complete_code, const String &, const String &, Object *)
396
397
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<CodeCompletionOption> *r_options, bool &r_force, String &r_call_hint) override {
398
Dictionary ret;
399
GDVIRTUAL_CALL(_complete_code, p_code, p_path, p_owner, ret);
400
if (!ret.has("result")) {
401
return ERR_UNAVAILABLE;
402
}
403
404
if (r_options != nullptr && ret.has("options")) {
405
Array options = ret["options"];
406
for (const Variant &var : options) {
407
Dictionary op = var;
408
CodeCompletionOption option;
409
ERR_CONTINUE(!op.has("kind"));
410
option.kind = CodeCompletionKind(int(op["kind"]));
411
ERR_CONTINUE(!op.has("display"));
412
option.display = op["display"];
413
ERR_CONTINUE(!op.has("insert_text"));
414
option.insert_text = op["insert_text"];
415
ERR_CONTINUE(!op.has("font_color"));
416
option.font_color = op["font_color"];
417
ERR_CONTINUE(!op.has("icon"));
418
option.icon = op["icon"];
419
ERR_CONTINUE(!op.has("default_value"));
420
option.default_value = op["default_value"];
421
ERR_CONTINUE(!op.has("location"));
422
option.location = op["location"];
423
if (op.has("matches")) {
424
PackedInt32Array matches = op["matches"];
425
ERR_CONTINUE(matches.size() & 1);
426
for (int j = 0; j < matches.size(); j += 2) {
427
option.matches.push_back(Pair<int, int>(matches[j], matches[j + 1]));
428
}
429
}
430
r_options->push_back(option);
431
}
432
}
433
434
ERR_FAIL_COND_V(!ret.has("force"), ERR_UNAVAILABLE);
435
r_force = ret["force"];
436
ERR_FAIL_COND_V(!ret.has("call_hint"), ERR_UNAVAILABLE);
437
r_call_hint = ret["call_hint"];
438
ERR_FAIL_COND_V(!ret.has("result"), ERR_UNAVAILABLE);
439
Error result = Error(int(ret["result"]));
440
441
return result;
442
}
443
444
GDVIRTUAL4RC_REQUIRED(Dictionary, _lookup_code, const String &, const String &, const String &, Object *)
445
446
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override {
447
Dictionary ret;
448
GDVIRTUAL_CALL(_lookup_code, p_code, p_symbol, p_path, p_owner, ret);
449
450
ERR_FAIL_COND_V(!ret.has("result"), ERR_UNAVAILABLE);
451
const Error result = Error(int(ret["result"]));
452
453
ERR_FAIL_COND_V(!ret.has("type"), ERR_UNAVAILABLE);
454
r_result.type = LookupResultType(int(ret["type"]));
455
456
r_result.class_name = ret.get("class_name", "");
457
r_result.class_member = ret.get("class_member", "");
458
459
r_result.description = ret.get("description", "");
460
r_result.is_deprecated = ret.get("is_deprecated", false);
461
r_result.deprecated_message = ret.get("deprecated_message", "");
462
r_result.is_experimental = ret.get("is_experimental", false);
463
r_result.experimental_message = ret.get("experimental_message", "");
464
465
r_result.doc_type = ret.get("doc_type", "");
466
r_result.enumeration = ret.get("enumeration", "");
467
r_result.is_bitfield = ret.get("is_bitfield", false);
468
469
r_result.value = ret.get("value", "");
470
471
r_result.script = ret.get("script", Ref<Script>());
472
r_result.script_path = ret.get("script_path", "");
473
r_result.location = ret.get("location", -1);
474
475
return result;
476
}
477
478
GDVIRTUAL3RC_REQUIRED(String, _auto_indent_code, const String &, int, int)
479
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override {
480
String ret;
481
GDVIRTUAL_CALL(_auto_indent_code, p_code, p_from_line, p_to_line, ret);
482
p_code = ret;
483
}
484
EXBIND2(add_global_constant, const StringName &, const Variant &)
485
EXBIND2(add_named_global_constant, const StringName &, const Variant &)
486
EXBIND1(remove_named_global_constant, const StringName &)
487
488
/* MULTITHREAD FUNCTIONS */
489
490
//some VMs need to be notified of thread creation/exiting to allocate a stack
491
EXBIND0(thread_enter)
492
EXBIND0(thread_exit)
493
494
EXBIND0RC(String, debug_get_error)
495
EXBIND0RC(int, debug_get_stack_level_count)
496
EXBIND1RC(int, debug_get_stack_level_line, int)
497
EXBIND1RC(String, debug_get_stack_level_function, int)
498
EXBIND1RC(String, debug_get_stack_level_source, int)
499
500
GDVIRTUAL3R_REQUIRED(Dictionary, _debug_get_stack_level_locals, int, int, int)
501
virtual void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override {
502
Dictionary ret;
503
GDVIRTUAL_CALL(_debug_get_stack_level_locals, p_level, p_max_subitems, p_max_depth, ret);
504
if (ret.is_empty()) {
505
return;
506
}
507
if (p_locals != nullptr && ret.has("locals")) {
508
PackedStringArray strings = ret["locals"];
509
for (int i = 0; i < strings.size(); i++) {
510
p_locals->push_back(strings[i]);
511
}
512
}
513
if (p_values != nullptr && ret.has("values")) {
514
Array values = ret["values"];
515
for (const Variant &value : values) {
516
p_values->push_back(value);
517
}
518
}
519
}
520
GDVIRTUAL3R_REQUIRED(Dictionary, _debug_get_stack_level_members, int, int, int)
521
virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override {
522
Dictionary ret;
523
GDVIRTUAL_CALL(_debug_get_stack_level_members, p_level, p_max_subitems, p_max_depth, ret);
524
if (ret.is_empty()) {
525
return;
526
}
527
if (p_members != nullptr && ret.has("members")) {
528
PackedStringArray strings = ret["members"];
529
for (int i = 0; i < strings.size(); i++) {
530
p_members->push_back(strings[i]);
531
}
532
}
533
if (p_values != nullptr && ret.has("values")) {
534
Array values = ret["values"];
535
for (const Variant &value : values) {
536
p_values->push_back(value);
537
}
538
}
539
}
540
GDVIRTUAL1R_REQUIRED(GDExtensionPtr<void>, _debug_get_stack_level_instance, int)
541
542
virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override {
543
GDExtensionPtr<void> ret = nullptr;
544
GDVIRTUAL_CALL(_debug_get_stack_level_instance, p_level, ret);
545
return reinterpret_cast<ScriptInstance *>(ret.operator void *());
546
}
547
GDVIRTUAL2R_REQUIRED(Dictionary, _debug_get_globals, int, int)
548
virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override {
549
Dictionary ret;
550
GDVIRTUAL_CALL(_debug_get_globals, p_max_subitems, p_max_depth, ret);
551
if (ret.is_empty()) {
552
return;
553
}
554
if (p_globals != nullptr && ret.has("globals")) {
555
PackedStringArray strings = ret["globals"];
556
for (int i = 0; i < strings.size(); i++) {
557
p_globals->push_back(strings[i]);
558
}
559
}
560
if (p_values != nullptr && ret.has("values")) {
561
Array values = ret["values"];
562
for (const Variant &value : values) {
563
p_values->push_back(value);
564
}
565
}
566
}
567
568
EXBIND4R(String, debug_parse_stack_level_expression, int, const String &, int, int)
569
570
GDVIRTUAL0R_REQUIRED(TypedArray<Dictionary>, _debug_get_current_stack_info)
571
virtual Vector<StackInfo> debug_get_current_stack_info() override {
572
TypedArray<Dictionary> ret;
573
GDVIRTUAL_CALL(_debug_get_current_stack_info, ret);
574
Vector<StackInfo> sret;
575
for (const Variant &var : ret) {
576
StackInfo si;
577
Dictionary d = var;
578
ERR_CONTINUE(!d.has("file"));
579
ERR_CONTINUE(!d.has("func"));
580
ERR_CONTINUE(!d.has("line"));
581
si.file = d["file"];
582
si.func = d["func"];
583
si.line = d["line"];
584
sret.push_back(si);
585
}
586
return sret;
587
}
588
589
EXBIND0(reload_all_scripts)
590
EXBIND2(reload_scripts, const Array &, bool)
591
EXBIND2(reload_tool_script, const Ref<Script> &, bool)
592
/* LOADER FUNCTIONS */
593
594
GDVIRTUAL0RC_REQUIRED(PackedStringArray, _get_recognized_extensions)
595
596
virtual void get_recognized_extensions(List<String> *p_extensions) const override {
597
PackedStringArray ret;
598
GDVIRTUAL_CALL(_get_recognized_extensions, ret);
599
for (int i = 0; i < ret.size(); i++) {
600
p_extensions->push_back(ret[i]);
601
}
602
}
603
604
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_public_functions)
605
virtual void get_public_functions(List<MethodInfo> *p_functions) const override {
606
TypedArray<Dictionary> ret;
607
GDVIRTUAL_CALL(_get_public_functions, ret);
608
for (const Variant &var : ret) {
609
MethodInfo mi = MethodInfo::from_dict(var);
610
p_functions->push_back(mi);
611
}
612
}
613
GDVIRTUAL0RC_REQUIRED(Dictionary, _get_public_constants)
614
virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override {
615
Dictionary ret;
616
GDVIRTUAL_CALL(_get_public_constants, ret);
617
for (int i = 0; i < ret.size(); i++) {
618
Dictionary d = ret[i];
619
ERR_CONTINUE(!d.has("name"));
620
ERR_CONTINUE(!d.has("value"));
621
p_constants->push_back(Pair<String, Variant>(d["name"], d["value"]));
622
}
623
}
624
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_public_annotations)
625
virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override {
626
TypedArray<Dictionary> ret;
627
GDVIRTUAL_CALL(_get_public_annotations, ret);
628
for (const Variant &var : ret) {
629
MethodInfo mi = MethodInfo::from_dict(var);
630
p_annotations->push_back(mi);
631
}
632
}
633
634
EXBIND0(profiling_start)
635
EXBIND0(profiling_stop)
636
EXBIND1(profiling_set_save_native_calls, bool)
637
638
GDVIRTUAL2R_REQUIRED(int, _profiling_get_accumulated_data, GDExtensionPtr<ScriptLanguageExtensionProfilingInfo>, int)
639
640
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override {
641
int ret = 0;
642
GDVIRTUAL_CALL(_profiling_get_accumulated_data, p_info_arr, p_info_max, ret);
643
return ret;
644
}
645
646
GDVIRTUAL2R_REQUIRED(int, _profiling_get_frame_data, GDExtensionPtr<ScriptLanguageExtensionProfilingInfo>, int)
647
648
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override {
649
int ret = 0;
650
GDVIRTUAL_CALL(_profiling_get_frame_data, p_info_arr, p_info_max, ret);
651
return ret;
652
}
653
654
EXBIND0(frame)
655
656
EXBIND1RC(bool, handles_global_class_type, const String &)
657
658
GDVIRTUAL1RC_REQUIRED(Dictionary, _get_global_class_name, const String &)
659
660
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr, bool *r_is_abstract = nullptr, bool *r_is_tool = nullptr) const override {
661
Dictionary ret;
662
GDVIRTUAL_CALL(_get_global_class_name, p_path, ret);
663
if (!ret.has("name")) {
664
return String();
665
}
666
if (r_base_type != nullptr && ret.has("base_type")) {
667
*r_base_type = ret["base_type"];
668
}
669
if (r_icon_path != nullptr && ret.has("icon_path")) {
670
*r_icon_path = ret["icon_path"];
671
}
672
if (r_is_abstract != nullptr && ret.has("is_abstract")) {
673
*r_is_abstract = ret["is_abstract"];
674
}
675
if (r_is_tool != nullptr && ret.has("is_tool")) {
676
*r_is_tool = ret["is_tool"];
677
}
678
return ret["name"];
679
}
680
};
681
682
VARIANT_ENUM_CAST(ScriptLanguageExtension::LookupResultType)
683
VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionKind)
684
VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionLocation)
685
686
class ScriptInstanceExtension : public ScriptInstance {
687
public:
688
const GDExtensionScriptInstanceInfo3 *native_info;
689
690
#ifndef DISABLE_DEPRECATED
691
bool free_native_info = false;
692
struct DeprecatedNativeInfo {
693
GDExtensionScriptInstanceNotification notification_func = nullptr;
694
GDExtensionScriptInstanceFreePropertyList free_property_list_func = nullptr;
695
GDExtensionScriptInstanceFreeMethodList free_method_list_func = nullptr;
696
};
697
DeprecatedNativeInfo *deprecated_native_info = nullptr;
698
#endif // DISABLE_DEPRECATED
699
700
GDExtensionScriptInstanceDataPtr instance = nullptr;
701
702
GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wignored-qualifiers") // There should not be warnings on explicit casts.
703
704
virtual bool set(const StringName &p_name, const Variant &p_value) override {
705
if (native_info->set_func) {
706
return native_info->set_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionConstVariantPtr)&p_value);
707
}
708
return false;
709
}
710
virtual bool get(const StringName &p_name, Variant &r_ret) const override {
711
if (native_info->get_func) {
712
return native_info->get_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&r_ret);
713
}
714
return false;
715
}
716
virtual void get_property_list(List<PropertyInfo> *p_list) const override {
717
if (native_info->get_property_list_func) {
718
uint32_t pcount;
719
const GDExtensionPropertyInfo *pinfo = native_info->get_property_list_func(instance, &pcount);
720
721
#ifdef TOOLS_ENABLED
722
if (pcount > 0) {
723
if (native_info->get_class_category_func) {
724
GDExtensionPropertyInfo gdext_class_category;
725
if (native_info->get_class_category_func(instance, &gdext_class_category)) {
726
p_list->push_back(PropertyInfo(gdext_class_category));
727
}
728
} else {
729
Ref<Script> script = get_script();
730
if (script.is_valid()) {
731
p_list->push_back(script->get_class_category());
732
}
733
}
734
}
735
#endif // TOOLS_ENABLED
736
737
for (uint32_t i = 0; i < pcount; i++) {
738
p_list->push_back(PropertyInfo(pinfo[i]));
739
}
740
if (native_info->free_property_list_func) {
741
native_info->free_property_list_func(instance, pinfo, pcount);
742
#ifndef DISABLE_DEPRECATED
743
} else if (deprecated_native_info && deprecated_native_info->free_property_list_func) {
744
deprecated_native_info->free_property_list_func(instance, pinfo);
745
#endif // DISABLE_DEPRECATED
746
}
747
}
748
}
749
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const override {
750
if (native_info->get_property_type_func) {
751
GDExtensionBool is_valid = 0;
752
GDExtensionVariantType type = native_info->get_property_type_func(instance, (GDExtensionConstStringNamePtr)&p_name, &is_valid);
753
if (r_is_valid) {
754
*r_is_valid = is_valid != 0;
755
}
756
return Variant::Type(type);
757
}
758
return Variant::NIL;
759
}
760
virtual void validate_property(PropertyInfo &p_property) const override {
761
if (native_info->validate_property_func) {
762
// GDExtension uses a StringName rather than a String for property name.
763
StringName prop_name = p_property.name;
764
GDExtensionPropertyInfo gdext_prop = {
765
(GDExtensionVariantType)p_property.type,
766
&prop_name,
767
&p_property.class_name,
768
(uint32_t)p_property.hint,
769
&p_property.hint_string,
770
p_property.usage,
771
};
772
if (native_info->validate_property_func(instance, &gdext_prop)) {
773
p_property.type = (Variant::Type)gdext_prop.type;
774
p_property.name = *reinterpret_cast<StringName *>(gdext_prop.name);
775
p_property.class_name = *reinterpret_cast<StringName *>(gdext_prop.class_name);
776
p_property.hint = (PropertyHint)gdext_prop.hint;
777
p_property.hint_string = *reinterpret_cast<String *>(gdext_prop.hint_string);
778
p_property.usage = gdext_prop.usage;
779
}
780
}
781
}
782
783
virtual bool property_can_revert(const StringName &p_name) const override {
784
if (native_info->property_can_revert_func) {
785
return native_info->property_can_revert_func(instance, (GDExtensionConstStringNamePtr)&p_name);
786
}
787
return false;
788
}
789
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const override {
790
if (native_info->property_get_revert_func) {
791
return native_info->property_get_revert_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&r_ret);
792
}
793
return false;
794
}
795
796
virtual Object *get_owner() override {
797
if (native_info->get_owner_func) {
798
return (Object *)native_info->get_owner_func(instance);
799
}
800
return nullptr;
801
}
802
static void _add_property_with_state(GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value, void *p_userdata) {
803
List<Pair<StringName, Variant>> *state = (List<Pair<StringName, Variant>> *)p_userdata;
804
state->push_back(Pair<StringName, Variant>(*(const StringName *)p_name, *(const Variant *)p_value));
805
}
806
virtual void get_property_state(List<Pair<StringName, Variant>> &state) override {
807
if (native_info->get_property_state_func) {
808
native_info->get_property_state_func(instance, _add_property_with_state, &state);
809
return;
810
}
811
ScriptInstance::get_property_state(state);
812
}
813
814
virtual void get_method_list(List<MethodInfo> *p_list) const override {
815
if (native_info->get_method_list_func) {
816
uint32_t mcount;
817
const GDExtensionMethodInfo *minfo = native_info->get_method_list_func(instance, &mcount);
818
for (uint32_t i = 0; i < mcount; i++) {
819
p_list->push_back(MethodInfo(minfo[i]));
820
}
821
if (native_info->free_method_list_func) {
822
native_info->free_method_list_func(instance, minfo, mcount);
823
#ifndef DISABLE_DEPRECATED
824
} else if (deprecated_native_info && deprecated_native_info->free_method_list_func) {
825
deprecated_native_info->free_method_list_func(instance, minfo);
826
#endif // DISABLE_DEPRECATED
827
}
828
}
829
}
830
virtual bool has_method(const StringName &p_method) const override {
831
if (native_info->has_method_func) {
832
return native_info->has_method_func(instance, (GDExtensionStringNamePtr)&p_method);
833
}
834
return false;
835
}
836
837
virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override {
838
if (native_info->get_method_argument_count_func) {
839
GDExtensionBool is_valid = 0;
840
GDExtensionInt ret = native_info->get_method_argument_count_func(instance, (GDExtensionStringNamePtr)&p_method, &is_valid);
841
if (r_is_valid) {
842
*r_is_valid = is_valid != 0;
843
}
844
return ret;
845
}
846
// Fallback to default.
847
return ScriptInstance::get_method_argument_count(p_method, r_is_valid);
848
}
849
850
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override {
851
Variant ret;
852
if (native_info->call_func) {
853
GDExtensionCallError ce;
854
native_info->call_func(instance, (GDExtensionConstStringNamePtr)&p_method, (GDExtensionConstVariantPtr *)p_args, p_argcount, (GDExtensionVariantPtr)&ret, &ce);
855
r_error.error = Callable::CallError::Error(ce.error);
856
r_error.argument = ce.argument;
857
r_error.expected = ce.expected;
858
}
859
return ret;
860
}
861
862
virtual void notification(int p_notification, bool p_reversed = false) override {
863
if (native_info->notification_func) {
864
native_info->notification_func(instance, p_notification, p_reversed);
865
#ifndef DISABLE_DEPRECATED
866
} else if (deprecated_native_info && deprecated_native_info->notification_func) {
867
deprecated_native_info->notification_func(instance, p_notification);
868
#endif // DISABLE_DEPRECATED
869
}
870
}
871
872
virtual String to_string(bool *r_valid) override {
873
if (native_info->to_string_func) {
874
GDExtensionBool valid;
875
String ret;
876
native_info->to_string_func(instance, &valid, reinterpret_cast<GDExtensionStringPtr>(&ret));
877
if (r_valid) {
878
*r_valid = valid != 0;
879
}
880
return ret;
881
}
882
return String();
883
}
884
885
virtual void refcount_incremented() override {
886
if (native_info->refcount_incremented_func) {
887
native_info->refcount_incremented_func(instance);
888
}
889
}
890
virtual bool refcount_decremented() override {
891
if (native_info->refcount_decremented_func) {
892
return native_info->refcount_decremented_func(instance);
893
}
894
return false;
895
}
896
897
virtual Ref<Script> get_script() const override {
898
if (native_info->get_script_func) {
899
GDExtensionObjectPtr script = native_info->get_script_func(instance);
900
return Ref<Script>(reinterpret_cast<Script *>(script));
901
}
902
return Ref<Script>();
903
}
904
905
virtual bool is_placeholder() const override {
906
if (native_info->is_placeholder_func) {
907
return native_info->is_placeholder_func(instance);
908
}
909
return false;
910
}
911
912
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) override {
913
if (native_info->set_fallback_func) {
914
bool ret = native_info->set_fallback_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionConstVariantPtr)&p_value);
915
if (r_valid) {
916
*r_valid = ret;
917
}
918
}
919
}
920
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid) override {
921
Variant ret;
922
if (native_info->get_fallback_func) {
923
bool valid = native_info->get_fallback_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&ret);
924
if (r_valid) {
925
*r_valid = valid;
926
}
927
}
928
return ret;
929
}
930
931
virtual ScriptLanguage *get_language() override {
932
if (native_info->get_language_func) {
933
GDExtensionScriptLanguagePtr lang = native_info->get_language_func(instance);
934
return reinterpret_cast<ScriptLanguage *>(lang);
935
}
936
return nullptr;
937
}
938
virtual ~ScriptInstanceExtension() {
939
if (native_info->free_func) {
940
native_info->free_func(instance);
941
}
942
#ifndef DISABLE_DEPRECATED
943
if (free_native_info) {
944
memfree(const_cast<GDExtensionScriptInstanceInfo3 *>(native_info));
945
}
946
if (deprecated_native_info) {
947
memfree(deprecated_native_info);
948
}
949
#endif // DISABLE_DEPRECATED
950
}
951
952
GODOT_GCC_WARNING_POP
953
};
954
955