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