gdscript.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  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. #ifndef GDSCRIPT_H
  31. #define GDSCRIPT_H
  32. #include "gdscript_function.h"
  33. #include "core/debugger/engine_debugger.h"
  34. #include "core/debugger/script_debugger.h"
  35. #include "core/doc_data.h"
  36. #include "core/io/resource_loader.h"
  37. #include "core/io/resource_saver.h"
  38. #include "core/object/script_language.h"
  39. #include "core/templates/rb_set.h"
  40. class GDScriptNativeClass : public RefCounted {
  41. GDCLASS(GDScriptNativeClass, RefCounted);
  42. StringName name;
  43. protected:
  44. bool _get(const StringName &p_name, Variant &r_ret) const;
  45. static void _bind_methods();
  46. public:
  47. _FORCE_INLINE_ const StringName &get_name() const { return name; }
  48. Variant _new();
  49. Object *instantiate();
  50. virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
  51. GDScriptNativeClass(const StringName &p_name);
  52. };
  53. class GDScript : public Script {
  54. GDCLASS(GDScript, Script);
  55. bool tool = false;
  56. bool valid = false;
  57. bool reloading = false;
  58. struct MemberInfo {
  59. int index = 0;
  60. StringName setter;
  61. StringName getter;
  62. GDScriptDataType data_type;
  63. PropertyInfo property_info;
  64. };
  65. struct ClearData {
  66. RBSet<GDScriptFunction *> functions;
  67. RBSet<Ref<Script>> scripts;
  68. void clear() {
  69. functions.clear();
  70. scripts.clear();
  71. }
  72. };
  73. friend class GDScriptInstance;
  74. friend class GDScriptFunction;
  75. friend class GDScriptAnalyzer;
  76. friend class GDScriptCompiler;
  77. friend class GDScriptDocGen;
  78. friend class GDScriptLambdaCallable;
  79. friend class GDScriptLambdaSelfCallable;
  80. friend class GDScriptLanguage;
  81. friend struct GDScriptUtilityFunctionsDefinitions;
  82. Ref<GDScriptNativeClass> native;
  83. Ref<GDScript> base;
  84. GDScript *_base = nullptr; //fast pointer access
  85. GDScript *_owner = nullptr; //for subclasses
  86. // Members are just indices to the instantiated script.
  87. HashMap<StringName, MemberInfo> member_indices; // Includes member info of all base GDScript classes.
  88. HashSet<StringName> members; // Only members of the current class.
  89. // Only static variables of the current class.
  90. HashMap<StringName, MemberInfo> static_variables_indices;
  91. Vector<Variant> static_variables; // Static variable values.
  92. HashMap<StringName, Variant> constants;
  93. HashMap<StringName, GDScriptFunction *> member_functions;
  94. HashMap<StringName, Ref<GDScript>> subclasses;
  95. HashMap<StringName, MethodInfo> _signals;
  96. Dictionary rpc_config;
  97. struct LambdaInfo {
  98. int capture_count;
  99. bool use_self;
  100. };
  101. HashMap<GDScriptFunction *, LambdaInfo> lambda_info;
  102. // List is used here because a ptr to elements are stored, so the memory locations need to be stable
  103. struct UpdatableFuncPtr {
  104. List<GDScriptFunction **> ptrs;
  105. Mutex mutex;
  106. bool initialized : 1;
  107. bool transferred : 1;
  108. uint32_t rc = 1;
  109. UpdatableFuncPtr() :
  110. initialized(false), transferred(false) {}
  111. };
  112. struct UpdatableFuncPtrElement {
  113. List<GDScriptFunction **>::Element *element = nullptr;
  114. UpdatableFuncPtr *func_ptr = nullptr;
  115. };
  116. static UpdatableFuncPtr func_ptrs_to_update_main_thread;
  117. static thread_local UpdatableFuncPtr *func_ptrs_to_update_thread_local;
  118. List<UpdatableFuncPtr *> func_ptrs_to_update;
  119. Mutex func_ptrs_to_update_mutex;
  120. UpdatableFuncPtrElement _add_func_ptr_to_update(GDScriptFunction **p_func_ptr_ptr);
  121. static void _remove_func_ptr_to_update(const UpdatableFuncPtrElement &p_func_ptr_element);
  122. static void _fixup_thread_function_bookkeeping();
  123. #ifdef TOOLS_ENABLED
  124. // For static data storage during hot-reloading.
  125. HashMap<StringName, MemberInfo> old_static_variables_indices;
  126. Vector<Variant> old_static_variables;
  127. void _save_old_static_data();
  128. void _restore_old_static_data();
  129. HashMap<StringName, int> member_lines;
  130. HashMap<StringName, Variant> member_default_values;
  131. List<PropertyInfo> members_cache;
  132. HashMap<StringName, Variant> member_default_values_cache;
  133. Ref<GDScript> base_cache;
  134. HashSet<ObjectID> inheriters_cache;
  135. bool source_changed_cache = false;
  136. bool placeholder_fallback_enabled = false;
  137. void _update_exports_values(HashMap<StringName, Variant> &values, List<PropertyInfo> &propnames);
  138. DocData::ClassDoc doc;
  139. Vector<DocData::ClassDoc> docs;
  140. void _clear_doc();
  141. void _add_doc(const DocData::ClassDoc &p_inner_class);
  142. #endif
  143. GDScriptFunction *implicit_initializer = nullptr;
  144. GDScriptFunction *initializer = nullptr; //direct pointer to new , faster to locate
  145. GDScriptFunction *implicit_ready = nullptr;
  146. GDScriptFunction *static_initializer = nullptr;
  147. Error _static_init();
  148. int subclass_count = 0;
  149. RBSet<Object *> instances;
  150. bool destructing = false;
  151. bool clearing = false;
  152. //exported members
  153. String source;
  154. String path;
  155. bool path_valid = false; // False if using default path.
  156. StringName local_name; // Inner class identifier or `class_name`.
  157. StringName global_name; // `class_name`.
  158. String fully_qualified_name;
  159. String simplified_icon_path;
  160. SelfList<GDScript> script_list;
  161. SelfList<GDScriptFunctionState>::List pending_func_states;
  162. GDScriptFunction *_super_constructor(GDScript *p_script);
  163. void _super_implicit_constructor(GDScript *p_script, GDScriptInstance *p_instance, Callable::CallError &r_error);
  164. GDScriptInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error);
  165. String _get_debug_path() const;
  166. #ifdef TOOLS_ENABLED
  167. HashSet<PlaceHolderScriptInstance *> placeholders;
  168. //void _update_placeholder(PlaceHolderScriptInstance *p_placeholder);
  169. virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override;
  170. void _update_exports_down(bool p_base_exports_changed);
  171. #endif
  172. #ifdef DEBUG_ENABLED
  173. HashMap<ObjectID, List<Pair<StringName, Variant>>> pending_reload_state;
  174. #endif
  175. bool _update_exports(bool *r_err = nullptr, bool p_recursive_call = false, PlaceHolderScriptInstance *p_instance_to_update = nullptr, bool p_base_exports_changed = false);
  176. void _save_orphaned_subclasses(GDScript::ClearData *p_clear_data);
  177. void _get_script_property_list(List<PropertyInfo> *r_list, bool p_include_base) const;
  178. void _get_script_method_list(List<MethodInfo> *r_list, bool p_include_base) const;
  179. void _get_script_signal_list(List<MethodInfo> *r_list, bool p_include_base) const;
  180. GDScript *_get_gdscript_from_variant(const Variant &p_variant);
  181. void _get_dependencies(RBSet<GDScript *> &p_dependencies, const GDScript *p_except);
  182. protected:
  183. bool _get(const StringName &p_name, Variant &r_ret) const;
  184. bool _set(const StringName &p_name, const Variant &p_value);
  185. void _get_property_list(List<PropertyInfo> *p_properties) const;
  186. Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
  187. static void _bind_methods();
  188. public:
  189. #ifdef DEBUG_ENABLED
  190. static String debug_get_script_name(const Ref<Script> &p_script);
  191. #endif
  192. _FORCE_INLINE_ StringName get_local_name() const { return local_name; }
  193. void clear(GDScript::ClearData *p_clear_data = nullptr);
  194. virtual bool is_valid() const override { return valid; }
  195. virtual bool is_abstract() const override { return false; } // GDScript does not support abstract classes.
  196. bool inherits_script(const Ref<Script> &p_script) const override;
  197. GDScript *find_class(const String &p_qualified_name);
  198. bool has_class(const GDScript *p_script);
  199. GDScript *get_root_script();
  200. bool is_root_script() const { return _owner == nullptr; }
  201. String get_fully_qualified_name() const { return fully_qualified_name; }
  202. const HashMap<StringName, Ref<GDScript>> &get_subclasses() const { return subclasses; }
  203. const HashMap<StringName, Variant> &get_constants() const { return constants; }
  204. const HashSet<StringName> &get_members() const { return members; }
  205. const GDScriptDataType &get_member_type(const StringName &p_member) const {
  206. CRASH_COND(!member_indices.has(p_member));
  207. return member_indices[p_member].data_type;
  208. }
  209. const HashMap<StringName, GDScriptFunction *> &get_member_functions() const { return member_functions; }
  210. const Ref<GDScriptNativeClass> &get_native() const { return native; }
  211. RBSet<GDScript *> get_dependencies();
  212. HashMap<GDScript *, RBSet<GDScript *>> get_all_dependencies();
  213. RBSet<GDScript *> get_must_clear_dependencies();
  214. virtual bool has_script_signal(const StringName &p_signal) const override;
  215. virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override;
  216. bool is_tool() const override { return tool; }
  217. Ref<GDScript> get_base() const;
  218. const HashMap<StringName, MemberInfo> &debug_get_member_indices() const { return member_indices; }
  219. const HashMap<StringName, GDScriptFunction *> &debug_get_member_functions() const; //this is debug only
  220. StringName debug_get_member_by_index(int p_idx) const;
  221. StringName debug_get_static_var_by_index(int p_idx) const;
  222. Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  223. virtual bool can_instantiate() const override;
  224. virtual Ref<Script> get_base_script() const override;
  225. virtual StringName get_global_name() const override;
  226. virtual StringName get_instance_base_type() const override; // this may not work in all scripts, will return empty if so
  227. virtual ScriptInstance *instance_create(Object *p_this) override;
  228. virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override;
  229. virtual bool instance_has(const Object *p_this) const override;
  230. virtual bool has_source_code() const override;
  231. virtual String get_source_code() const override;
  232. virtual void set_source_code(const String &p_code) override;
  233. virtual void update_exports() override;
  234. #ifdef TOOLS_ENABLED
  235. virtual Vector<DocData::ClassDoc> get_documentation() const override {
  236. return docs;
  237. }
  238. virtual String get_class_icon_path() const override;
  239. #endif // TOOLS_ENABLED
  240. virtual Error reload(bool p_keep_state = false) override;
  241. virtual void set_path(const String &p_path, bool p_take_over = false) override;
  242. String get_script_path() const;
  243. Error load_source_code(const String &p_path);
  244. bool get_property_default_value(const StringName &p_property, Variant &r_value) const override;
  245. virtual void get_script_method_list(List<MethodInfo> *p_list) const override;
  246. virtual bool has_method(const StringName &p_method) const override;
  247. virtual bool has_static_method(const StringName &p_method) const override;
  248. virtual MethodInfo get_method_info(const StringName &p_method) const override;
  249. virtual void get_script_property_list(List<PropertyInfo> *p_list) const override;
  250. virtual ScriptLanguage *get_language() const override;
  251. virtual int get_member_line(const StringName &p_member) const override {
  252. #ifdef TOOLS_ENABLED
  253. if (member_lines.has(p_member)) {
  254. return member_lines[p_member];
  255. }
  256. #endif
  257. return -1;
  258. }
  259. virtual void get_constants(HashMap<StringName, Variant> *p_constants) override;
  260. virtual void get_members(HashSet<StringName> *p_members) override;
  261. virtual const Variant get_rpc_config() const override;
  262. void unload_static() const;
  263. #ifdef TOOLS_ENABLED
  264. virtual bool is_placeholder_fallback_enabled() const override { return placeholder_fallback_enabled; }
  265. #endif
  266. GDScript();
  267. ~GDScript();
  268. };
  269. class GDScriptInstance : public ScriptInstance {
  270. friend class GDScript;
  271. friend class GDScriptFunction;
  272. friend class GDScriptLambdaCallable;
  273. friend class GDScriptLambdaSelfCallable;
  274. friend class GDScriptCompiler;
  275. friend class GDScriptCache;
  276. friend struct GDScriptUtilityFunctionsDefinitions;
  277. ObjectID owner_id;
  278. Object *owner = nullptr;
  279. Ref<GDScript> script;
  280. #ifdef DEBUG_ENABLED
  281. HashMap<StringName, int> member_indices_cache; //used only for hot script reloading
  282. #endif
  283. Vector<Variant> members;
  284. bool base_ref_counted;
  285. SelfList<GDScriptFunctionState>::List pending_func_states;
  286. public:
  287. virtual Object *get_owner() { return owner; }
  288. virtual bool set(const StringName &p_name, const Variant &p_value);
  289. virtual bool get(const StringName &p_name, Variant &r_ret) const;
  290. virtual void get_property_list(List<PropertyInfo> *p_properties) const;
  291. virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const;
  292. virtual void validate_property(PropertyInfo &p_property) const;
  293. virtual bool property_can_revert(const StringName &p_name) const;
  294. virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const;
  295. virtual void get_method_list(List<MethodInfo> *p_list) const;
  296. virtual bool has_method(const StringName &p_method) const;
  297. virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  298. Variant debug_get_member_by_index(int p_idx) const { return members[p_idx]; }
  299. virtual void notification(int p_notification, bool p_reversed = false);
  300. String to_string(bool *r_valid);
  301. virtual Ref<Script> get_script() const;
  302. virtual ScriptLanguage *get_language();
  303. void set_path(const String &p_path);
  304. void reload_members();
  305. virtual const Variant get_rpc_config() const;
  306. GDScriptInstance();
  307. ~GDScriptInstance();
  308. };
  309. class GDScriptLanguage : public ScriptLanguage {
  310. friend class GDScriptFunctionState;
  311. static GDScriptLanguage *singleton;
  312. Variant *_global_array = nullptr;
  313. Vector<Variant> global_array;
  314. HashMap<StringName, int> globals;
  315. HashMap<StringName, Variant> named_globals;
  316. struct CallLevel {
  317. Variant *stack = nullptr;
  318. GDScriptFunction *function = nullptr;
  319. GDScriptInstance *instance = nullptr;
  320. int *ip = nullptr;
  321. int *line = nullptr;
  322. };
  323. static thread_local int _debug_parse_err_line;
  324. static thread_local String _debug_parse_err_file;
  325. static thread_local String _debug_error;
  326. struct CallStack {
  327. CallLevel *levels = nullptr;
  328. int stack_pos = 0;
  329. void free() {
  330. if (levels) {
  331. memdelete(levels);
  332. levels = nullptr;
  333. }
  334. }
  335. ~CallStack() {
  336. free();
  337. }
  338. };
  339. static thread_local CallStack _call_stack;
  340. int _debug_max_call_stack = 0;
  341. void _add_global(const StringName &p_name, const Variant &p_value);
  342. friend class GDScriptInstance;
  343. Mutex mutex;
  344. friend class GDScript;
  345. SelfList<GDScript>::List script_list;
  346. friend class GDScriptFunction;
  347. SelfList<GDScriptFunction>::List function_list;
  348. bool profiling;
  349. uint64_t script_frame_time;
  350. HashMap<String, ObjectID> orphan_subclasses;
  351. public:
  352. int calls;
  353. bool debug_break(const String &p_error, bool p_allow_continue = true);
  354. bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
  355. _FORCE_INLINE_ void enter_function(GDScriptInstance *p_instance, GDScriptFunction *p_function, Variant *p_stack, int *p_ip, int *p_line) {
  356. if (unlikely(_call_stack.levels == nullptr)) {
  357. _call_stack.levels = memnew_arr(CallLevel, _debug_max_call_stack + 1);
  358. }
  359. if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) {
  360. EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() + 1);
  361. }
  362. if (_call_stack.stack_pos >= _debug_max_call_stack) {
  363. //stack overflow
  364. _debug_error = vformat("Stack overflow (stack size: %s). Check for infinite recursion in your script.", _debug_max_call_stack);
  365. EngineDebugger::get_script_debugger()->debug(this);
  366. return;
  367. }
  368. _call_stack.levels[_call_stack.stack_pos].stack = p_stack;
  369. _call_stack.levels[_call_stack.stack_pos].instance = p_instance;
  370. _call_stack.levels[_call_stack.stack_pos].function = p_function;
  371. _call_stack.levels[_call_stack.stack_pos].ip = p_ip;
  372. _call_stack.levels[_call_stack.stack_pos].line = p_line;
  373. _call_stack.stack_pos++;
  374. }
  375. _FORCE_INLINE_ void exit_function() {
  376. if (EngineDebugger::get_script_debugger()->get_lines_left() > 0 && EngineDebugger::get_script_debugger()->get_depth() >= 0) {
  377. EngineDebugger::get_script_debugger()->set_depth(EngineDebugger::get_script_debugger()->get_depth() - 1);
  378. }
  379. if (_call_stack.stack_pos == 0) {
  380. _debug_error = "Stack Underflow (Engine Bug)";
  381. EngineDebugger::get_script_debugger()->debug(this);
  382. return;
  383. }
  384. _call_stack.stack_pos--;
  385. }
  386. virtual Vector<StackInfo> debug_get_current_stack_info() override {
  387. Vector<StackInfo> csi;
  388. csi.resize(_call_stack.stack_pos);
  389. for (int i = 0; i < _call_stack.stack_pos; i++) {
  390. csi.write[_call_stack.stack_pos - i - 1].line = _call_stack.levels[i].line ? *_call_stack.levels[i].line : 0;
  391. if (_call_stack.levels[i].function) {
  392. csi.write[_call_stack.stack_pos - i - 1].func = _call_stack.levels[i].function->get_name();
  393. csi.write[_call_stack.stack_pos - i - 1].file = _call_stack.levels[i].function->get_script()->get_script_path();
  394. }
  395. }
  396. return csi;
  397. }
  398. struct {
  399. StringName _init;
  400. StringName _static_init;
  401. StringName _notification;
  402. StringName _set;
  403. StringName _get;
  404. StringName _get_property_list;
  405. StringName _validate_property;
  406. StringName _property_can_revert;
  407. StringName _property_get_revert;
  408. StringName _script_source;
  409. } strings;
  410. _FORCE_INLINE_ int get_global_array_size() const { return global_array.size(); }
  411. _FORCE_INLINE_ Variant *get_global_array() { return _global_array; }
  412. _FORCE_INLINE_ const HashMap<StringName, int> &get_global_map() const { return globals; }
  413. _FORCE_INLINE_ const HashMap<StringName, Variant> &get_named_globals_map() const { return named_globals; }
  414. // These two functions should be used when behavior needs to be consistent between in-editor and running the scene
  415. bool has_any_global_constant(const StringName &p_name) { return named_globals.has(p_name) || globals.has(p_name); }
  416. Variant get_any_global_constant(const StringName &p_name);
  417. _FORCE_INLINE_ static GDScriptLanguage *get_singleton() { return singleton; }
  418. virtual String get_name() const override;
  419. /* LANGUAGE FUNCTIONS */
  420. virtual void init() override;
  421. virtual String get_type() const override;
  422. virtual String get_extension() const override;
  423. virtual void finish() override;
  424. /* EDITOR FUNCTIONS */
  425. virtual void get_reserved_words(List<String> *p_words) const override;
  426. virtual bool is_control_flow_keyword(String p_keywords) const override;
  427. virtual void get_comment_delimiters(List<String> *p_delimiters) const override;
  428. virtual void get_doc_comment_delimiters(List<String> *p_delimiters) const override;
  429. virtual void get_string_delimiters(List<String> *p_delimiters) const override;
  430. virtual bool is_using_templates() override;
  431. virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override;
  432. virtual Vector<ScriptTemplate> get_built_in_templates(StringName p_object) override;
  433. 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;
  434. virtual Script *create_script() const override;
  435. #ifndef DISABLE_DEPRECATED
  436. virtual bool has_named_classes() const override { return false; }
  437. #endif
  438. virtual bool supports_builtin_mode() const override;
  439. virtual bool supports_documentation() const override;
  440. virtual bool can_inherit_from_file() const override { return true; }
  441. virtual int find_function(const String &p_function, const String &p_code) const override;
  442. virtual String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
  443. 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;
  444. #ifdef TOOLS_ENABLED
  445. virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override;
  446. #endif
  447. virtual String _get_indentation() const;
  448. virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override;
  449. virtual void add_global_constant(const StringName &p_variable, const Variant &p_value) override;
  450. virtual void add_named_global_constant(const StringName &p_name, const Variant &p_value) override;
  451. virtual void remove_named_global_constant(const StringName &p_name) override;
  452. /* MULTITHREAD FUNCTIONS */
  453. virtual void thread_enter() override;
  454. virtual void thread_exit() override;
  455. /* DEBUGGER FUNCTIONS */
  456. virtual String debug_get_error() const override;
  457. virtual int debug_get_stack_level_count() const override;
  458. virtual int debug_get_stack_level_line(int p_level) const override;
  459. virtual String debug_get_stack_level_function(int p_level) const override;
  460. virtual String debug_get_stack_level_source(int p_level) const override;
  461. 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;
  462. 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;
  463. virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override;
  464. virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override;
  465. 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;
  466. virtual void reload_all_scripts() override;
  467. virtual void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override;
  468. virtual void frame() override;
  469. virtual void get_public_functions(List<MethodInfo> *p_functions) const override;
  470. virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override;
  471. virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override;
  472. virtual void profiling_start() override;
  473. virtual void profiling_stop() override;
  474. virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override;
  475. virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override;
  476. /* LOADER FUNCTIONS */
  477. virtual void get_recognized_extensions(List<String> *p_extensions) const override;
  478. /* GLOBAL CLASSES */
  479. virtual bool handles_global_class_type(const String &p_type) const override;
  480. virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const override;
  481. void add_orphan_subclass(const String &p_qualified_name, const ObjectID &p_subclass);
  482. Ref<GDScript> get_orphan_subclass(const String &p_qualified_name);
  483. Ref<GDScript> get_script_by_fully_qualified_name(const String &p_name);
  484. GDScriptLanguage();
  485. ~GDScriptLanguage();
  486. };
  487. class ResourceFormatLoaderGDScript : public ResourceFormatLoader {
  488. public:
  489. 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);
  490. virtual void get_recognized_extensions(List<String> *p_extensions) const;
  491. virtual bool handles_type(const String &p_type) const;
  492. virtual String get_resource_type(const String &p_path) const;
  493. virtual void get_dependencies(const String &p_path, List<String> *p_dependencies, bool p_add_types = false);
  494. };
  495. class ResourceFormatSaverGDScript : public ResourceFormatSaver {
  496. public:
  497. virtual Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0);
  498. virtual void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const;
  499. virtual bool recognize(const Ref<Resource> &p_resource) const;
  500. };
  501. #endif // GDSCRIPT_H