Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/modules/gdscript/gdscript.h
11351 views
1
/**************************************************************************/
2
/* gdscript.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 "gdscript_function.h"
34
35
#include "core/debugger/engine_debugger.h"
36
#include "core/debugger/script_debugger.h"
37
#include "core/doc_data.h"
38
#include "core/io/resource_loader.h"
39
#include "core/io/resource_saver.h"
40
#include "core/object/script_language.h"
41
#include "core/templates/rb_set.h"
42
43
class GDScriptNativeClass : public RefCounted {
44
GDCLASS(GDScriptNativeClass, RefCounted);
45
46
StringName name;
47
48
protected:
49
bool _get(const StringName &p_name, Variant &r_ret) const;
50
static void _bind_methods();
51
52
public:
53
_FORCE_INLINE_ const StringName &get_name() const { return name; }
54
Variant _new();
55
Object *instantiate();
56
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
57
GDScriptNativeClass(const StringName &p_name);
58
};
59
60
class GDScript : public Script {
61
GDCLASS(GDScript, Script);
62
bool tool = false;
63
bool valid = false;
64
bool reloading = false;
65
bool _is_abstract = false;
66
67
struct MemberInfo {
68
int index = 0;
69
StringName setter;
70
StringName getter;
71
GDScriptDataType data_type;
72
PropertyInfo property_info;
73
};
74
75
struct ClearData {
76
RBSet<GDScriptFunction *> functions;
77
RBSet<Ref<Script>> scripts;
78
void clear() {
79
functions.clear();
80
scripts.clear();
81
}
82
};
83
84
friend class GDScriptInstance;
85
friend class GDScriptFunction;
86
friend class GDScriptAnalyzer;
87
friend class GDScriptCompiler;
88
friend class GDScriptDocGen;
89
friend class GDScriptLambdaCallable;
90
friend class GDScriptLambdaSelfCallable;
91
friend class GDScriptLanguage;
92
friend struct GDScriptUtilityFunctionsDefinitions;
93
94
Ref<GDScriptNativeClass> native;
95
Ref<GDScript> base;
96
GDScript *_base = nullptr; //fast pointer access
97
GDScript *_owner = nullptr; //for subclasses
98
99
// Members are just indices to the instantiated script.
100
HashMap<StringName, MemberInfo> member_indices; // Includes member info of all base GDScript classes.
101
HashSet<StringName> members; // Only members of the current class.
102
103
// Only static variables of the current class.
104
HashMap<StringName, MemberInfo> static_variables_indices;
105
Vector<Variant> static_variables; // Static variable values.
106
107
HashMap<StringName, Variant> constants;
108
HashMap<StringName, GDScriptFunction *> member_functions;
109
HashMap<StringName, Ref<GDScript>> subclasses;
110
HashMap<StringName, MethodInfo> _signals;
111
Dictionary rpc_config;
112
113
public:
114
struct LambdaInfo {
115
int capture_count;
116
bool use_self;
117
};
118
119
private:
120
HashMap<GDScriptFunction *, LambdaInfo> lambda_info;
121
122
public:
123
class UpdatableFuncPtr {
124
friend class GDScript;
125
126
GDScriptFunction *ptr = nullptr;
127
GDScript *script = nullptr;
128
List<UpdatableFuncPtr *>::Element *list_element = nullptr;
129
130
public:
131
GDScriptFunction *operator->() const { return ptr; }
132
operator GDScriptFunction *() const { return ptr; }
133
134
UpdatableFuncPtr(GDScriptFunction *p_function);
135
~UpdatableFuncPtr();
136
};
137
138
private:
139
// List is used here because a ptr to elements are stored, so the memory locations need to be stable
140
List<UpdatableFuncPtr *> func_ptrs_to_update;
141
Mutex func_ptrs_to_update_mutex;
142
143
void _recurse_replace_function_ptrs(const HashMap<GDScriptFunction *, GDScriptFunction *> &p_replacements) const;
144
145
#ifdef TOOLS_ENABLED
146
// For static data storage during hot-reloading.
147
HashMap<StringName, MemberInfo> old_static_variables_indices;
148
Vector<Variant> old_static_variables;
149
void _save_old_static_data();
150
void _restore_old_static_data();
151
152
HashMap<StringName, int> member_lines;
153
HashMap<StringName, Variant> member_default_values;
154
List<PropertyInfo> members_cache;
155
HashMap<StringName, Variant> member_default_values_cache;
156
Ref<GDScript> base_cache;
157
HashSet<ObjectID> inheriters_cache;
158
bool source_changed_cache = false;
159
bool placeholder_fallback_enabled = false;
160
void _update_exports_values(HashMap<StringName, Variant> &values, List<PropertyInfo> &propnames);
161
162
StringName doc_class_name;
163
DocData::ClassDoc doc;
164
Vector<DocData::ClassDoc> docs;
165
void _add_doc(const DocData::ClassDoc &p_doc);
166
void _clear_doc();
167
#endif
168
169
GDScriptFunction *initializer = nullptr; // Direct pointer to `new()`/`_init()` member function, faster to locate.
170
171
GDScriptFunction *implicit_initializer = nullptr; // `@implicit_new()` special function.
172
GDScriptFunction *implicit_ready = nullptr; // `@implicit_ready()` special function.
173
GDScriptFunction *static_initializer = nullptr; // `@static_initializer()` special function.
174
175
Error _static_init();
176
void _static_default_init(); // Initialize static variables with default values based on their types.
177
178
int subclass_count = 0;
179
RBSet<Object *> instances;
180
bool destructing = false;
181
bool clearing = false;
182
//exported members
183
String source;
184
Vector<uint8_t> binary_tokens;
185
String path;
186
bool path_valid = false; // False if using default path.
187
StringName local_name; // Inner class identifier or `class_name`.
188
StringName global_name; // `class_name`.
189
String fully_qualified_name;
190
String simplified_icon_path;
191
SelfList<GDScript> script_list;
192
193
SelfList<GDScriptFunctionState>::List pending_func_states;
194
195
GDScriptFunction *_super_constructor(GDScript *p_script);
196
void _super_implicit_constructor(GDScript *p_script, GDScriptInstance *p_instance, Callable::CallError &r_error);
197
GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, Callable::CallError &r_error);
198
199
String _get_debug_path() const;
200
201
#ifdef TOOLS_ENABLED
202
HashSet<PlaceHolderScriptInstance *> placeholders;
203
//void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
204
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override;
205
void _update_exports_down(bool p_base_exports_changed);
206
#endif
207
208
#ifdef DEBUG_ENABLED
209
HashMap<ObjectID, List<Pair<StringName, Variant>>> pending_reload_state;
210
#endif
211
212
bool _update_exports(bool *r_err = nullptr, bool p_recursive_call = false, PlaceHolderScriptInstance *p_instance_to_update = nullptr, bool p_base_exports_changed = false);
213
214
void _save_orphaned_subclasses(GDScript::ClearData *p_clear_data);
215
216
void _get_script_property_list(List<PropertyInfo> *r_list, bool p_include_base) const;
217
void _get_script_method_list(List<MethodInfo> *r_list, bool p_include_base) const;
218
void _get_script_signal_list(List<MethodInfo> *r_list, bool p_include_base) const;
219
220
GDScript *_get_gdscript_from_variant(const Variant &p_variant);
221
void _collect_function_dependencies(GDScriptFunction *p_func, RBSet<GDScript *> &p_dependencies, const GDScript *p_except);
222
void _collect_dependencies(RBSet<GDScript *> &p_dependencies, const GDScript *p_except);
223
224
protected:
225
bool _get(const StringName &p_name, Variant &r_ret) const;
226
bool _set(const StringName &p_name, const Variant &p_value);
227
void _get_property_list(List<PropertyInfo> *p_properties) const;
228
229
Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
230
231
static void _bind_methods();
232
233
public:
234
#ifdef DEBUG_ENABLED
235
static String debug_get_script_name(const Ref<Script> &p_script);
236
#endif
237
238
static String canonicalize_path(const String &p_path);
239
_FORCE_INLINE_ static bool is_canonically_equal_paths(const String &p_path_a, const String &p_path_b) {
240
return canonicalize_path(p_path_a) == canonicalize_path(p_path_b);
241
}
242
243
_FORCE_INLINE_ StringName get_local_name() const { return local_name; }
244
245
void clear(GDScript::ClearData *p_clear_data = nullptr);
246
247
// Cancels all functions of the script that are are waiting to be resumed after using await.
248
void cancel_pending_functions(bool warn);
249
250
virtual bool is_valid() const override { return valid; }
251
252
bool inherits_script(const Ref<Script> &p_script) const override;
253
254
GDScript *find_class(const String &p_qualified_name);
255
bool has_class(const GDScript *p_script);
256
GDScript *get_root_script();
257
bool is_root_script() const { return _owner == nullptr; }
258
String get_fully_qualified_name() const { return fully_qualified_name; }
259
const HashMap<StringName, Ref<GDScript>> &get_subclasses() const { return subclasses; }
260
const HashMap<StringName, Variant> &get_constants() const { return constants; }
261
const HashSet<StringName> &get_members() const { return members; }
262
const GDScriptDataType &get_member_type(const StringName &p_member) const {
263
CRASH_COND(!member_indices.has(p_member));
264
return member_indices[p_member].data_type;
265
}
266
const Ref<GDScriptNativeClass> &get_native() const { return native; }
267
268
_FORCE_INLINE_ const HashMap<StringName, GDScriptFunction *> &get_member_functions() const { return member_functions; }
269
_FORCE_INLINE_ const HashMap<GDScriptFunction *, LambdaInfo> &get_lambda_info() const { return lambda_info; }
270
271
_FORCE_INLINE_ const GDScriptFunction *get_implicit_initializer() const { return implicit_initializer; }
272
_FORCE_INLINE_ const GDScriptFunction *get_implicit_ready() const { return implicit_ready; }
273
_FORCE_INLINE_ const GDScriptFunction *get_static_initializer() const { return static_initializer; }
274
275
RBSet<GDScript *> get_dependencies();
276
HashMap<GDScript *, RBSet<GDScript *>> get_all_dependencies();
277
RBSet<GDScript *> get_must_clear_dependencies();
278
279
virtual bool has_script_signal(const StringName &p_signal) const override;
280
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override;
281
282
bool is_tool() const override { return tool; }
283
bool is_abstract() const override { return _is_abstract; }
284
Ref<GDScript> get_base() const;
285
286
const HashMap<StringName, MemberInfo> &debug_get_member_indices() const { return member_indices; }
287
const HashMap<StringName, GDScriptFunction *> &debug_get_member_functions() const; //this is debug only
288
StringName debug_get_member_by_index(int p_idx) const;
289
StringName debug_get_static_var_by_index(int p_idx) const;
290
291
Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
292
virtual bool can_instantiate() const override;
293
294
virtual Ref<Script> get_base_script() const override;
295
virtual StringName get_global_name() const override;
296
297
virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so
298
virtual ScriptInstance *instance_create(Object *p_this) override;
299
virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override;
300
virtual bool instance_has(const Object *p_this) const override;
301
302
virtual bool has_source_code() const override;
303
virtual String get_source_code() const override;
304
virtual void set_source_code(const String &p_code) override;
305
virtual void update_exports() override;
306
307
#ifdef TOOLS_ENABLED
308
virtual StringName get_doc_class_name() const override { return doc_class_name; }
309
virtual Vector<DocData::ClassDoc> get_documentation() const override { return docs; }
310
virtual String get_class_icon_path() const override;
311
#endif // TOOLS_ENABLED
312
313
virtual Error reload(bool p_keep_state = false) override;
314
315
virtual void set_path(const String &p_path, bool p_take_over = false) override;
316
String get_script_path() const;
317
Error load_source_code(const String &p_path);
318
319
void set_binary_tokens_source(const Vector<uint8_t> &p_binary_tokens);
320
const Vector<uint8_t> &get_binary_tokens_source() const;
321
Vector<uint8_t> get_as_binary_tokens() const;
322
323
bool get_property_default_value(const StringName &p_property, Variant &r_value) const override;
324
325
virtual void get_script_method_list(List<MethodInfo> *p_list) const override;
326
virtual bool has_method(const StringName &p_method) const override;
327
virtual bool has_static_method(const StringName &p_method) const override;
328
329
virtual int get_script_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override;
330
331
virtual MethodInfo get_method_info(const StringName &p_method) const override;
332
333
virtual void get_script_property_list(List<PropertyInfo> *p_list) const override;
334
335
virtual ScriptLanguage *get_language() const override;
336
337
virtual int get_member_line(const StringName &p_member) const override {
338
#ifdef TOOLS_ENABLED
339
if (member_lines.has(p_member)) {
340
return member_lines[p_member];
341
}
342
#endif
343
return -1;
344
}
345
346
virtual void get_constants(HashMap<StringName, Variant> *p_constants) override;
347
virtual void get_members(HashSet<StringName> *p_members) override;
348
349
virtual const Variant get_rpc_config() const override;
350
351
void unload_static() const;
352
353
#ifdef TOOLS_ENABLED
354
virtual bool is_placeholder_fallback_enabled() const override { return placeholder_fallback_enabled; }
355
#endif
356
357
GDScript();
358
~GDScript();
359
};
360
361
class GDScriptInstance : public ScriptInstance {
362
friend class GDScript;
363
friend class GDScriptFunction;
364
friend class GDScriptLambdaCallable;
365
friend class GDScriptLambdaSelfCallable;
366
friend class GDScriptCompiler;
367
friend class GDScriptCache;
368
friend struct GDScriptUtilityFunctionsDefinitions;
369
370
ObjectID owner_id;
371
Object *owner = nullptr;
372
Ref<GDScript> script;
373
#ifdef DEBUG_ENABLED
374
HashMap<StringName, int> member_indices_cache; //used only for hot script reloading
375
#endif
376
Vector<Variant> members;
377
378
SelfList<GDScriptFunctionState>::List pending_func_states;
379
380
void _call_implicit_ready_recursively(GDScript *p_script);
381
382
public:
383
virtual Object *get_owner() { return owner; }
384
385
virtual bool set(const StringName &p_name, const Variant &p_value);
386
virtual bool get(const StringName &p_name, Variant &r_ret) const;
387
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
388
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const;
389
virtual void validate_property(PropertyInfo &p_property) const;
390
391
virtual bool property_can_revert(const StringName &p_name) const;
392
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const;
393
394
virtual void get_method_list(List<MethodInfo> *p_list) const;
395
virtual bool has_method(const StringName &p_method) const;
396
397
virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const;
398
399
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
400
401
Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; }
402
403
virtual void notification(int p_notification, bool p_reversed = false);
404
String to_string(bool *r_valid);
405
406
virtual Ref<Script> get_script() const;
407
408
virtual ScriptLanguage *get_language();
409
410
void set_path(const String &p_path);
411
412
void reload_members();
413
414
virtual const Variant get_rpc_config() const;
415
416
GDScriptInstance() {}
417
~GDScriptInstance();
418
};
419
420
class GDScriptLanguage : public ScriptLanguage {
421
friend class GDScriptFunctionState;
422
423
static GDScriptLanguage *singleton;
424
425
bool finishing = false;
426
427
Variant *_global_array = nullptr;
428
Vector<Variant> global_array;
429
HashMap<StringName, int> globals;
430
HashMap<StringName, Variant> named_globals;
431
Vector<int> global_array_empty_indexes;
432
433
struct CallLevel {
434
Variant *stack = nullptr;
435
GDScriptFunction *function = nullptr;
436
GDScriptInstance *instance = nullptr;
437
int *ip = nullptr;
438
int *line = nullptr;
439
CallLevel *prev = nullptr; // Reverse linked list (stack).
440
};
441
442
static thread_local int _debug_parse_err_line;
443
static thread_local String _debug_parse_err_file;
444
static thread_local String _debug_error;
445
446
static thread_local CallLevel *_call_stack;
447
static thread_local uint32_t _call_stack_size;
448
uint32_t _debug_max_call_stack = 0;
449
450
bool track_call_stack = false;
451
bool track_locals = false;
452
453
static CallLevel *_get_stack_level(uint32_t p_level);
454
455
void _add_global(const StringName &p_name, const Variant &p_value);
456
void _remove_global(const StringName &p_name);
457
458
friend class GDScriptInstance;
459
460
Mutex mutex;
461
462
friend class GDScript;
463
464
SelfList<GDScript>::List script_list;
465
friend class GDScriptFunction;
466
467
SelfList<GDScriptFunction>::List function_list;
468
#ifdef DEBUG_ENABLED
469
bool profiling;
470
bool profile_native_calls;
471
uint64_t script_frame_time;
472
#endif
473
474
HashMap<String, ObjectID> orphan_subclasses;
475
476
#ifdef TOOLS_ENABLED
477
void _extension_loaded(const Ref<GDExtension> &p_extension);
478
void _extension_unloading(const Ref<GDExtension> &p_extension);
479
#endif
480
481
public:
482
bool debug_break(const String &p_error, bool p_allow_continue = true);
483
bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
484
485
_FORCE_INLINE_ void enter_function(CallLevel *call_level, GDScriptInstance *p_instance, GDScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) {
486
if (!track_call_stack) {
487
return;
488
}
489
490
#ifdef DEBUG_ENABLED
491
ScriptDebugger *script_debugger = EngineDebugger::get_script_debugger();
492
if (script_debugger != nullptr && script_debugger->get_lines_left() > 0 && script_debugger->get_depth() >= 0) {
493
script_debugger->set_depth(script_debugger->get_depth() + 1);
494
}
495
#endif
496
497
if (unlikely(_call_stack_size >= _debug_max_call_stack)) {
498
_debug_error = vformat("Stack overflow (stack size: %s). Check for infinite recursion in your script.", _debug_max_call_stack);
499
500
#ifdef DEBUG_ENABLED
501
if (script_debugger != nullptr) {
502
script_debugger->debug(this);
503
}
504
#endif
505
506
return;
507
}
508
509
call_level->prev = _call_stack;
510
_call_stack = call_level;
511
call_level->stack = p_stack;
512
call_level->instance = p_instance;
513
call_level->function = p_function;
514
call_level->ip = p_ip;
515
call_level->line = p_line;
516
_call_stack_size++;
517
}
518
519
_FORCE_INLINE_ void exit_function() {
520
if (!track_call_stack) {
521
return;
522
}
523
524
#ifdef DEBUG_ENABLED
525
ScriptDebugger *script_debugger = EngineDebugger::get_script_debugger();
526
if (script_debugger && script_debugger->get_lines_left() > 0 && script_debugger->get_depth() >= 0) {
527
script_debugger->set_depth(script_debugger->get_depth() - 1);
528
}
529
#endif
530
531
if (unlikely(_call_stack_size == 0)) {
532
#ifdef DEBUG_ENABLED
533
if (script_debugger) {
534
_debug_error = "Stack Underflow (Engine Bug)";
535
script_debugger->debug(this);
536
} else {
537
ERR_PRINT("Stack underflow! (Engine Bug)");
538
}
539
#else // !DEBUG_ENABLED
540
ERR_PRINT("Stack underflow! (Engine Bug)");
541
#endif
542
return;
543
}
544
545
_call_stack_size--;
546
_call_stack = _call_stack->prev;
547
}
548
549
virtual Vector<StackInfo> debug_get_current_stack_info() override {
550
Vector<StackInfo> csi;
551
csi.resize(_call_stack_size);
552
CallLevel *cl = _call_stack;
553
uint32_t idx = 0;
554
while (cl) {
555
csi.write[idx].line = *cl->line;
556
if (cl->function) {
557
csi.write[idx].func = cl->function->get_name();
558
csi.write[idx].file = cl->function->get_script()->get_script_path();
559
}
560
idx++;
561
cl = cl->prev;
562
}
563
return csi;
564
}
565
566
struct {
567
StringName _init;
568
StringName _static_init;
569
StringName _notification;
570
StringName _set;
571
StringName _get;
572
StringName _get_property_list;
573
StringName _validate_property;
574
StringName _property_can_revert;
575
StringName _property_get_revert;
576
StringName _script_source;
577
578
} strings;
579
580
_FORCE_INLINE_ bool should_track_call_stack() const { return track_call_stack; }
581
_FORCE_INLINE_ bool should_track_locals() const { return track_locals; }
582
_FORCE_INLINE_ int get_global_array_size() const { return global_array.size(); }
583
_FORCE_INLINE_ Variant *get_global_array() { return _global_array; }
584
_FORCE_INLINE_ const HashMap<StringName, int> &get_global_map() const { return globals; }
585
_FORCE_INLINE_ const HashMap<StringName, Variant> &get_named_globals_map() const { return named_globals; }
586
// These two functions should be used when behavior needs to be consistent between in-editor and running the scene
587
bool has_any_global_constant(const StringName &p_name) { return named_globals.has(p_name) || globals.has(p_name); }
588
Variant get_any_global_constant(const StringName &p_name);
589
590
_FORCE_INLINE_ static GDScriptLanguage *get_singleton() { return singleton; }
591
592
virtual String get_name() const override;
593
594
/* LANGUAGE FUNCTIONS */
595
virtual void init() override;
596
virtual String get_type() const override;
597
virtual String get_extension() const override;
598
virtual void finish() override;
599
600
/* EDITOR FUNCTIONS */
601
virtual Vector<String> get_reserved_words() const override;
602
virtual bool is_control_flow_keyword(const String &p_keywords) const override;
603
virtual Vector<String> get_comment_delimiters() const override;
604
virtual Vector<String> get_doc_comment_delimiters() const override;
605
virtual Vector<String> get_string_delimiters() const override;
606
virtual bool is_using_templates() override;
607
virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override;
608
virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override;
609
virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override;
610
virtual Script *create_script() const override;
611
#ifndef DISABLE_DEPRECATED
612
virtual bool has_named_classes() const override { return false; }
613
#endif
614
virtual bool supports_builtin_mode() const override;
615
virtual bool supports_documentation() const override;
616
virtual bool can_inherit_from_file() const override { return true; }
617
virtual int find_function(const String &p_function, const String &p_code) const override;
618
virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
619
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<ScriptLanguage::CodeCompletionOption> *r_options, bool &r_forced, String &r_call_hint) override;
620
#ifdef TOOLS_ENABLED
621
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override;
622
#endif
623
virtual String _get_indentation() const;
624
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override;
625
virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) override;
626
virtual void add_named_global_constant(const StringName &p_name, const Variant &p_value) override;
627
virtual void remove_named_global_constant(const StringName &p_name) override;
628
629
/* DEBUGGER FUNCTIONS */
630
631
virtual String debug_get_error() const override;
632
virtual int debug_get_stack_level_count() const override;
633
virtual int debug_get_stack_level_line(int p_level) const override;
634
virtual String debug_get_stack_level_function(int p_level) const override;
635
virtual String debug_get_stack_level_source(int p_level) const override;
636
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;
637
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;
638
virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override;
639
virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
640
virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems = -1, int p_max_depth = -1) override;
641
642
virtual void reload_all_scripts() override;
643
virtual void reload_scripts(const Array &p_scripts, bool p_soft_reload) override;
644
virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override;
645
646
virtual void frame() override;
647
648
virtual void get_public_functions(List<MethodInfo> *p_functions) const override;
649
virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override;
650
virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override;
651
652
virtual void profiling_start() override;
653
virtual void profiling_stop() override;
654
virtual void profiling_set_save_native_calls(bool p_enable) override;
655
void profiling_collate_native_call_data(bool p_accumulated);
656
657
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override;
658
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override;
659
660
/* LOADER FUNCTIONS */
661
662
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
663
664
/* GLOBAL CLASSES */
665
666
virtual bool handles_global_class_type(const String &p_type) const override;
667
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;
668
669
void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass);
670
Ref<GDScript> get_orphan_subclass(const String &p_qualified_name);
671
672
Ref<GDScript> get_script_by_fully_qualified_name(const String &p_name);
673
674
GDScriptLanguage();
675
~GDScriptLanguage();
676
};
677
678
class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
679
GDSOFTCLASS(ResourceFormatLoaderGDScript, ResourceFormatLoader);
680
681
public:
682
virtual Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE) override;
683
virtual void get_recognized_extensions(List<String> *p_extensions) const override;
684
virtual bool handles_type(const String &p_type) const override;
685
virtual String get_resource_type(const String &p_path) const override;
686
virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false) override;
687
virtual void get_classes_used(const String &p_path, HashSet<StringName> *r_classes) override;
688
};
689
690
class ResourceFormatSaverGDScript : public ResourceFormatSaver {
691
GDSOFTCLASS(ResourceFormatSaverGDScript, ResourceFormatSaver);
692
693
public:
694
virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0) override;
695
virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const override;
696
virtual bool recognize(const Ref<Resource> &p_resource) const override;
697
};
698
699