Path: blob/master/core/object/script_language_extension.h
20936 views
/**************************************************************************/1/* script_language_extension.h */2/**************************************************************************/3/* This file is part of: */4/* GODOT ENGINE */5/* https://godotengine.org */6/**************************************************************************/7/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */8/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */9/* */10/* Permission is hereby granted, free of charge, to any person obtaining */11/* a copy of this software and associated documentation files (the */12/* "Software"), to deal in the Software without restriction, including */13/* without limitation the rights to use, copy, modify, merge, publish, */14/* distribute, sublicense, and/or sell copies of the Software, and to */15/* permit persons to whom the Software is furnished to do so, subject to */16/* the following conditions: */17/* */18/* The above copyright notice and this permission notice shall be */19/* included in all copies or substantial portions of the Software. */20/* */21/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */22/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */23/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */24/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */25/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */26/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */27/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */28/**************************************************************************/2930#pragma once3132#include "core/extension/ext_wrappers.gen.h"33#include "core/object/gdvirtual.gen.h"34#include "core/object/script_language.h"35#include "core/variant/native_ptr.h"36#include "core/variant/typed_array.h"3738class ScriptExtension : public Script {39GDCLASS(ScriptExtension, Script)4041protected:42EXBIND0R(bool, editor_can_reload_from_file)4344GDVIRTUAL1(_placeholder_erased, GDExtensionPtr<void>)45virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override {46GDVIRTUAL_CALL(_placeholder_erased, p_placeholder);47}4849static void _bind_methods();5051public:52EXBIND0RC(bool, can_instantiate)53EXBIND0RC(Ref<Script>, get_base_script)54EXBIND0RC(StringName, get_global_name)55EXBIND1RC(bool, inherits_script, const Ref<Script> &)56EXBIND0RC(StringName, get_instance_base_type)5758GDVIRTUAL1RC_REQUIRED(GDExtensionPtr<void>, _instance_create, Object *)59virtual ScriptInstance *instance_create(Object *p_this) override {60GDExtensionPtr<void> ret = nullptr;61GDVIRTUAL_CALL(_instance_create, p_this, ret);62return reinterpret_cast<ScriptInstance *>(ret.operator void *());63}64GDVIRTUAL1RC_REQUIRED(GDExtensionPtr<void>, _placeholder_instance_create, Object *)65PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override {66GDExtensionPtr<void> ret = nullptr;67GDVIRTUAL_CALL(_placeholder_instance_create, p_this, ret);68return reinterpret_cast<PlaceHolderScriptInstance *>(ret.operator void *());69}7071EXBIND1RC(bool, instance_has, const Object *)72EXBIND0RC(bool, has_source_code)73EXBIND0RC(String, get_source_code)74EXBIND1(set_source_code, const String &)75EXBIND1R(Error, reload, bool)7677GDVIRTUAL0RC_REQUIRED(StringName, _get_doc_class_name)78GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_documentation)79GDVIRTUAL0RC(String, _get_class_icon_path)80#ifdef TOOLS_ENABLED81virtual StringName get_doc_class_name() const override {82StringName ret;83GDVIRTUAL_CALL(_get_doc_class_name, ret);84return ret;85}8687virtual Vector<DocData::ClassDoc> get_documentation() const override {88TypedArray<Dictionary> doc;89GDVIRTUAL_CALL(_get_documentation, doc);9091Vector<DocData::ClassDoc> class_doc;92for (int i = 0; i < doc.size(); i++) {93class_doc.append(DocData::ClassDoc::from_dict(doc[i]));94}9596return class_doc;97}9899virtual String get_class_icon_path() const override {100String ret;101GDVIRTUAL_CALL(_get_class_icon_path, ret);102return ret;103}104#endif // TOOLS_ENABLED105106EXBIND1RC(bool, has_method, const StringName &)107EXBIND1RC(bool, has_static_method, const StringName &)108109GDVIRTUAL1RC(Variant, _get_script_method_argument_count, const StringName &)110virtual int get_script_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override {111Variant ret;112if (GDVIRTUAL_CALL(_get_script_method_argument_count, p_method, ret) && ret.get_type() == Variant::INT) {113if (r_is_valid) {114*r_is_valid = true;115}116return ret.operator int();117}118// Fallback to default.119return Script::get_script_method_argument_count(p_method, r_is_valid);120}121122GDVIRTUAL1RC_REQUIRED(Dictionary, _get_method_info, const StringName &)123virtual MethodInfo get_method_info(const StringName &p_method) const override {124Dictionary mi;125GDVIRTUAL_CALL(_get_method_info, p_method, mi);126return MethodInfo::from_dict(mi);127}128129EXBIND0RC(bool, is_tool)130EXBIND0RC(bool, is_valid)131132virtual bool is_abstract() const override {133bool abst;134return GDVIRTUAL_CALL(_is_abstract, abst) && abst;135}136GDVIRTUAL0RC(bool, _is_abstract)137138EXBIND0RC(ScriptLanguage *, get_language)139EXBIND1RC(bool, has_script_signal, const StringName &)140141GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_signal_list)142143virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override {144TypedArray<Dictionary> sl;145GDVIRTUAL_CALL(_get_script_signal_list, sl);146for (int i = 0; i < sl.size(); i++) {147r_signals->push_back(MethodInfo::from_dict(sl[i]));148}149}150151GDVIRTUAL1RC_REQUIRED(bool, _has_property_default_value, const StringName &)152GDVIRTUAL1RC_REQUIRED(Variant, _get_property_default_value, const StringName &)153154virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override {155bool has_dv = false;156if (!GDVIRTUAL_CALL(_has_property_default_value, p_property, has_dv) || !has_dv) {157return false;158}159Variant ret;160GDVIRTUAL_CALL(_get_property_default_value, p_property, ret);161r_value = ret;162return true;163}164165EXBIND0(update_exports)166167GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_method_list)168169virtual void get_script_method_list(List<MethodInfo> *r_methods) const override {170TypedArray<Dictionary> sl;171GDVIRTUAL_CALL(_get_script_method_list, sl);172for (int i = 0; i < sl.size(); i++) {173r_methods->push_back(MethodInfo::from_dict(sl[i]));174}175}176177GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_property_list)178179virtual void get_script_property_list(List<PropertyInfo> *r_propertys) const override {180TypedArray<Dictionary> sl;181GDVIRTUAL_CALL(_get_script_property_list, sl);182for (int i = 0; i < sl.size(); i++) {183r_propertys->push_back(PropertyInfo::from_dict(sl[i]));184}185}186187EXBIND1RC(int, get_member_line, const StringName &)188189GDVIRTUAL0RC_REQUIRED(Dictionary, _get_constants)190191virtual void get_constants(HashMap<StringName, Variant> *p_constants) override {192Dictionary constants;193GDVIRTUAL_CALL(_get_constants, constants);194for (const KeyValue<Variant, Variant> &kv : constants) {195p_constants->insert(kv.key, kv.value);196}197}198GDVIRTUAL0RC_REQUIRED(TypedArray<StringName>, _get_members)199virtual void get_members(HashSet<StringName> *p_members) override {200TypedArray<StringName> members;201GDVIRTUAL_CALL(_get_members, members);202for (int i = 0; i < members.size(); i++) {203p_members->insert(members[i]);204}205}206207EXBIND0RC(bool, is_placeholder_fallback_enabled)208209GDVIRTUAL0RC_REQUIRED(Variant, _get_rpc_config)210211virtual const Variant get_rpc_config() const override {212Variant ret;213GDVIRTUAL_CALL(_get_rpc_config, ret);214return ret;215}216};217218typedef ScriptLanguage::ProfilingInfo ScriptLanguageExtensionProfilingInfo;219220GDVIRTUAL_NATIVE_PTR(ScriptLanguageExtensionProfilingInfo)221222class ScriptLanguageExtension : public ScriptLanguage {223GDCLASS(ScriptLanguageExtension, ScriptLanguage)224protected:225static void _bind_methods();226227public:228EXBIND0RC(String, get_name)229230EXBIND0(init)231EXBIND0RC(String, get_type)232EXBIND0RC(String, get_extension)233EXBIND0(finish)234235/* EDITOR FUNCTIONS */236237GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_reserved_words)238239virtual Vector<String> get_reserved_words() const override {240Vector<String> ret;241GDVIRTUAL_CALL(_get_reserved_words, ret);242return ret;243}244EXBIND1RC(bool, is_control_flow_keyword, const String &)245246GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_comment_delimiters)247248virtual Vector<String> get_comment_delimiters() const override {249Vector<String> ret;250GDVIRTUAL_CALL(_get_comment_delimiters, ret);251return ret;252}253254GDVIRTUAL0RC(Vector<String>, _get_doc_comment_delimiters)255256virtual Vector<String> get_doc_comment_delimiters() const override {257Vector<String> ret;258GDVIRTUAL_CALL(_get_doc_comment_delimiters, ret);259return ret;260}261262GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_string_delimiters)263264virtual Vector<String> get_string_delimiters() const override {265Vector<String> ret;266GDVIRTUAL_CALL(_get_string_delimiters, ret);267return ret;268}269270EXBIND3RC(Ref<Script>, make_template, const String &, const String &, const String &)271272GDVIRTUAL1RC_REQUIRED(TypedArray<Dictionary>, _get_built_in_templates, StringName)273274virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override {275TypedArray<Dictionary> ret;276GDVIRTUAL_CALL(_get_built_in_templates, p_object, ret);277Vector<ScriptTemplate> stret;278for (int i = 0; i < ret.size(); i++) {279Dictionary d = ret[i];280ScriptTemplate st;281ERR_CONTINUE(!d.has("inherit"));282st.inherit = d["inherit"];283ERR_CONTINUE(!d.has("name"));284st.name = d["name"];285ERR_CONTINUE(!d.has("description"));286st.description = d["description"];287ERR_CONTINUE(!d.has("content"));288st.content = d["content"];289ERR_CONTINUE(!d.has("id"));290st.id = d["id"];291ERR_CONTINUE(!d.has("origin"));292st.origin = TemplateLocation(int(d["origin"]));293stret.push_back(st);294}295return stret;296}297298EXBIND0R(bool, is_using_templates)299300GDVIRTUAL6RC_REQUIRED(Dictionary, _validate, const String &, const String &, bool, bool, bool, bool)301virtual 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 {302Dictionary ret;303GDVIRTUAL_CALL(_validate, p_script, p_path, r_functions != nullptr, r_errors != nullptr, r_warnings != nullptr, r_safe_lines != nullptr, ret);304if (!ret.has("valid")) {305return false;306}307if (r_functions != nullptr && ret.has("functions")) {308Vector<String> functions = ret["functions"];309for (int i = 0; i < functions.size(); i++) {310r_functions->push_back(functions[i]);311}312}313if (r_errors != nullptr && ret.has("errors")) {314Array errors = ret["errors"];315for (const Variant &error : errors) {316Dictionary err = error;317ERR_CONTINUE(!err.has("line"));318ERR_CONTINUE(!err.has("column"));319ERR_CONTINUE(!err.has("message"));320321ScriptError serr;322if (err.has("path")) {323serr.path = err["path"];324}325serr.line = err["line"];326serr.column = err["column"];327serr.message = err["message"];328329r_errors->push_back(serr);330}331}332if (r_warnings != nullptr && ret.has("warnings")) {333ERR_FAIL_COND_V(!ret.has("warnings"), false);334Array warnings = ret["warnings"];335for (const Variant &warning : warnings) {336Dictionary warn = warning;337ERR_CONTINUE(!warn.has("start_line"));338ERR_CONTINUE(!warn.has("end_line"));339ERR_CONTINUE(!warn.has("code"));340ERR_CONTINUE(!warn.has("string_code"));341ERR_CONTINUE(!warn.has("message"));342343Warning swarn;344swarn.start_line = warn["start_line"];345swarn.end_line = warn["end_line"];346swarn.code = warn["code"];347swarn.string_code = warn["string_code"];348swarn.message = warn["message"];349350r_warnings->push_back(swarn);351}352}353if (r_safe_lines != nullptr && ret.has("safe_lines")) {354PackedInt32Array safe_lines = ret["safe_lines"];355for (int i = 0; i < safe_lines.size(); i++) {356r_safe_lines->insert(safe_lines[i]);357}358}359return ret["valid"];360}361362EXBIND1RC(String, validate_path, const String &)363#ifndef DISABLE_DEPRECATED364GDVIRTUAL0RC(Object *, _create_script)365GDVIRTUAL0RC(bool, _has_named_classes)366#endif367EXBIND0RC(bool, supports_builtin_mode)368EXBIND0RC(bool, supports_documentation)369EXBIND0RC(bool, can_inherit_from_file)370371EXBIND2RC(int, find_function, const String &, const String &)372EXBIND3RC(String, make_function, const String &, const String &, const PackedStringArray &)373EXBIND0RC(bool, can_make_function)374EXBIND3R(Error, open_in_external_editor, const Ref<Script> &, int, int)375EXBIND0R(bool, overrides_external_editor)376377GDVIRTUAL0RC(ScriptNameCasing, _preferred_file_name_casing);378379virtual ScriptNameCasing preferred_file_name_casing() const override {380ScriptNameCasing ret;381if (GDVIRTUAL_CALL(_preferred_file_name_casing, ret)) {382return ret;383}384return ScriptNameCasing::SCRIPT_NAME_CASING_SNAKE_CASE;385}386387GDVIRTUAL3RC_REQUIRED(Dictionary, _complete_code, const String &, const String &, Object *)388389virtual 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 {390Dictionary ret;391GDVIRTUAL_CALL(_complete_code, p_code, p_path, p_owner, ret);392if (!ret.has("result")) {393return ERR_UNAVAILABLE;394}395396if (r_options != nullptr && ret.has("options")) {397Array options = ret["options"];398for (const Variant &var : options) {399Dictionary op = var;400CodeCompletionOption option;401ERR_CONTINUE(!op.has("kind"));402option.kind = CodeCompletionKind(int(op["kind"]));403ERR_CONTINUE(!op.has("display"));404option.display = op["display"];405ERR_CONTINUE(!op.has("insert_text"));406option.insert_text = op["insert_text"];407ERR_CONTINUE(!op.has("font_color"));408option.font_color = op["font_color"];409ERR_CONTINUE(!op.has("icon"));410option.icon = op["icon"];411ERR_CONTINUE(!op.has("default_value"));412option.default_value = op["default_value"];413ERR_CONTINUE(!op.has("location"));414option.location = op["location"];415if (op.has("matches")) {416PackedInt32Array matches = op["matches"];417ERR_CONTINUE(matches.size() & 1);418for (int j = 0; j < matches.size(); j += 2) {419option.matches.push_back(Pair<int, int>(matches[j], matches[j + 1]));420}421}422option.matches_dirty = true;423r_options->push_back(option);424}425}426427ERR_FAIL_COND_V(!ret.has("force"), ERR_UNAVAILABLE);428r_force = ret["force"];429ERR_FAIL_COND_V(!ret.has("call_hint"), ERR_UNAVAILABLE);430r_call_hint = ret["call_hint"];431ERR_FAIL_COND_V(!ret.has("result"), ERR_UNAVAILABLE);432Error result = Error(int(ret["result"]));433434return result;435}436437GDVIRTUAL4RC_REQUIRED(Dictionary, _lookup_code, const String &, const String &, const String &, Object *)438439virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override {440Dictionary ret;441GDVIRTUAL_CALL(_lookup_code, p_code, p_symbol, p_path, p_owner, ret);442443ERR_FAIL_COND_V(!ret.has("result"), ERR_UNAVAILABLE);444const Error result = Error(int(ret["result"]));445446ERR_FAIL_COND_V(!ret.has("type"), ERR_UNAVAILABLE);447r_result.type = LookupResultType(int(ret["type"]));448449r_result.class_name = ret.get("class_name", "");450r_result.class_member = ret.get("class_member", "");451452r_result.description = ret.get("description", "");453r_result.is_deprecated = ret.get("is_deprecated", false);454r_result.deprecated_message = ret.get("deprecated_message", "");455r_result.is_experimental = ret.get("is_experimental", false);456r_result.experimental_message = ret.get("experimental_message", "");457458r_result.doc_type = ret.get("doc_type", "");459r_result.enumeration = ret.get("enumeration", "");460r_result.is_bitfield = ret.get("is_bitfield", false);461462r_result.value = ret.get("value", "");463464r_result.script = ret.get("script", Ref<Script>());465r_result.script_path = ret.get("script_path", "");466r_result.location = ret.get("location", -1);467468return result;469}470471GDVIRTUAL3RC_REQUIRED(String, _auto_indent_code, const String &, int, int)472virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override {473String ret;474GDVIRTUAL_CALL(_auto_indent_code, p_code, p_from_line, p_to_line, ret);475p_code = ret;476}477EXBIND2(add_global_constant, const StringName &, const Variant &)478EXBIND2(add_named_global_constant, const StringName &, const Variant &)479EXBIND1(remove_named_global_constant, const StringName &)480481/* MULTITHREAD FUNCTIONS */482483//some VMs need to be notified of thread creation/exiting to allocate a stack484EXBIND0(thread_enter)485EXBIND0(thread_exit)486487EXBIND0RC(String, debug_get_error)488EXBIND0RC(int, debug_get_stack_level_count)489EXBIND1RC(int, debug_get_stack_level_line, int)490EXBIND1RC(String, debug_get_stack_level_function, int)491EXBIND1RC(String, debug_get_stack_level_source, int)492493GDVIRTUAL3R_REQUIRED(Dictionary, _debug_get_stack_level_locals, int, int, int)494virtual 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 {495Dictionary ret;496GDVIRTUAL_CALL(_debug_get_stack_level_locals, p_level, p_max_subitems, p_max_depth, ret);497if (ret.is_empty()) {498return;499}500if (p_locals != nullptr && ret.has("locals")) {501PackedStringArray strings = ret["locals"];502for (int i = 0; i < strings.size(); i++) {503p_locals->push_back(strings[i]);504}505}506if (p_values != nullptr && ret.has("values")) {507Array values = ret["values"];508for (const Variant &value : values) {509p_values->push_back(value);510}511}512}513GDVIRTUAL3R_REQUIRED(Dictionary, _debug_get_stack_level_members, int, int, int)514virtual 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 {515Dictionary ret;516GDVIRTUAL_CALL(_debug_get_stack_level_members, p_level, p_max_subitems, p_max_depth, ret);517if (ret.is_empty()) {518return;519}520if (p_members != nullptr && ret.has("members")) {521PackedStringArray strings = ret["members"];522for (int i = 0; i < strings.size(); i++) {523p_members->push_back(strings[i]);524}525}526if (p_values != nullptr && ret.has("values")) {527Array values = ret["values"];528for (const Variant &value : values) {529p_values->push_back(value);530}531}532}533GDVIRTUAL1R_REQUIRED(GDExtensionPtr<void>, _debug_get_stack_level_instance, int)534535virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override {536GDExtensionPtr<void> ret = nullptr;537GDVIRTUAL_CALL(_debug_get_stack_level_instance, p_level, ret);538return reinterpret_cast<ScriptInstance *>(ret.operator void *());539}540GDVIRTUAL2R_REQUIRED(Dictionary, _debug_get_globals, int, int)541virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override {542Dictionary ret;543GDVIRTUAL_CALL(_debug_get_globals, p_max_subitems, p_max_depth, ret);544if (ret.is_empty()) {545return;546}547if (p_globals != nullptr && ret.has("globals")) {548PackedStringArray strings = ret["globals"];549for (int i = 0; i < strings.size(); i++) {550p_globals->push_back(strings[i]);551}552}553if (p_values != nullptr && ret.has("values")) {554Array values = ret["values"];555for (const Variant &value : values) {556p_values->push_back(value);557}558}559}560561EXBIND4R(String, debug_parse_stack_level_expression, int, const String &, int, int)562563GDVIRTUAL0R_REQUIRED(TypedArray<Dictionary>, _debug_get_current_stack_info)564virtual Vector<StackInfo> debug_get_current_stack_info() override {565TypedArray<Dictionary> ret;566GDVIRTUAL_CALL(_debug_get_current_stack_info, ret);567Vector<StackInfo> sret;568for (const Variant &var : ret) {569StackInfo si;570Dictionary d = var;571ERR_CONTINUE(!d.has("file"));572ERR_CONTINUE(!d.has("func"));573ERR_CONTINUE(!d.has("line"));574si.file = d["file"];575si.func = d["func"];576si.line = d["line"];577sret.push_back(si);578}579return sret;580}581582EXBIND0(reload_all_scripts)583EXBIND2(reload_scripts, const Array &, bool)584EXBIND2(reload_tool_script, const Ref<Script> &, bool)585/* LOADER FUNCTIONS */586587GDVIRTUAL0RC_REQUIRED(PackedStringArray, _get_recognized_extensions)588589virtual void get_recognized_extensions(List<String> *p_extensions) const override {590PackedStringArray ret;591GDVIRTUAL_CALL(_get_recognized_extensions, ret);592for (int i = 0; i < ret.size(); i++) {593p_extensions->push_back(ret[i]);594}595}596597GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_public_functions)598virtual void get_public_functions(List<MethodInfo> *p_functions) const override {599TypedArray<Dictionary> ret;600GDVIRTUAL_CALL(_get_public_functions, ret);601for (const Variant &var : ret) {602MethodInfo mi = MethodInfo::from_dict(var);603p_functions->push_back(mi);604}605}606GDVIRTUAL0RC_REQUIRED(Dictionary, _get_public_constants)607virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override {608Dictionary ret;609GDVIRTUAL_CALL(_get_public_constants, ret);610for (int i = 0; i < ret.size(); i++) {611Dictionary d = ret[i];612ERR_CONTINUE(!d.has("name"));613ERR_CONTINUE(!d.has("value"));614p_constants->push_back(Pair<String, Variant>(d["name"], d["value"]));615}616}617GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_public_annotations)618virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override {619TypedArray<Dictionary> ret;620GDVIRTUAL_CALL(_get_public_annotations, ret);621for (const Variant &var : ret) {622MethodInfo mi = MethodInfo::from_dict(var);623p_annotations->push_back(mi);624}625}626627EXBIND0(profiling_start)628EXBIND0(profiling_stop)629EXBIND1(profiling_set_save_native_calls, bool)630631GDVIRTUAL2R_REQUIRED(int, _profiling_get_accumulated_data, GDExtensionPtr<ScriptLanguageExtensionProfilingInfo>, int)632633virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override {634int ret = 0;635GDVIRTUAL_CALL(_profiling_get_accumulated_data, p_info_arr, p_info_max, ret);636return ret;637}638639GDVIRTUAL2R_REQUIRED(int, _profiling_get_frame_data, GDExtensionPtr<ScriptLanguageExtensionProfilingInfo>, int)640641virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override {642int ret = 0;643GDVIRTUAL_CALL(_profiling_get_frame_data, p_info_arr, p_info_max, ret);644return ret;645}646647EXBIND0(frame)648649EXBIND1RC(bool, handles_global_class_type, const String &)650651GDVIRTUAL1RC_REQUIRED(Dictionary, _get_global_class_name, const String &)652653virtual 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 {654Dictionary ret;655GDVIRTUAL_CALL(_get_global_class_name, p_path, ret);656if (!ret.has("name")) {657return String();658}659if (r_base_type != nullptr && ret.has("base_type")) {660*r_base_type = ret["base_type"];661}662if (r_icon_path != nullptr && ret.has("icon_path")) {663*r_icon_path = ret["icon_path"];664}665if (r_is_abstract != nullptr && ret.has("is_abstract")) {666*r_is_abstract = ret["is_abstract"];667}668if (r_is_tool != nullptr && ret.has("is_tool")) {669*r_is_tool = ret["is_tool"];670}671return ret["name"];672}673};674675VARIANT_ENUM_CAST(ScriptLanguageExtension::LookupResultType)676VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionKind)677VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionLocation)678679class ScriptInstanceExtension : public ScriptInstance {680public:681const GDExtensionScriptInstanceInfo3 *native_info;682683#ifndef DISABLE_DEPRECATED684bool free_native_info = false;685struct DeprecatedNativeInfo {686GDExtensionScriptInstanceNotification notification_func = nullptr;687GDExtensionScriptInstanceFreePropertyList free_property_list_func = nullptr;688GDExtensionScriptInstanceFreeMethodList free_method_list_func = nullptr;689};690DeprecatedNativeInfo *deprecated_native_info = nullptr;691#endif // DISABLE_DEPRECATED692693GDExtensionScriptInstanceDataPtr instance = nullptr;694695GODOT_GCC_WARNING_PUSH_AND_IGNORE("-Wignored-qualifiers") // There should not be warnings on explicit casts.696697virtual bool set(const StringName &p_name, const Variant &p_value) override {698if (native_info->set_func) {699return native_info->set_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionConstVariantPtr)&p_value);700}701return false;702}703virtual bool get(const StringName &p_name, Variant &r_ret) const override {704if (native_info->get_func) {705return native_info->get_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&r_ret);706}707return false;708}709virtual void get_property_list(List<PropertyInfo> *p_list) const override {710if (native_info->get_property_list_func) {711uint32_t pcount;712const GDExtensionPropertyInfo *pinfo = native_info->get_property_list_func(instance, &pcount);713714#ifdef TOOLS_ENABLED715if (pcount > 0) {716if (native_info->get_class_category_func) {717GDExtensionPropertyInfo gdext_class_category;718if (native_info->get_class_category_func(instance, &gdext_class_category)) {719p_list->push_back(PropertyInfo(gdext_class_category));720}721} else {722Ref<Script> script = get_script();723if (script.is_valid()) {724p_list->push_back(script->get_class_category());725}726}727}728#endif // TOOLS_ENABLED729730for (uint32_t i = 0; i < pcount; i++) {731p_list->push_back(PropertyInfo(pinfo[i]));732}733if (native_info->free_property_list_func) {734native_info->free_property_list_func(instance, pinfo, pcount);735#ifndef DISABLE_DEPRECATED736} else if (deprecated_native_info && deprecated_native_info->free_property_list_func) {737deprecated_native_info->free_property_list_func(instance, pinfo);738#endif // DISABLE_DEPRECATED739}740}741}742virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const override {743if (native_info->get_property_type_func) {744GDExtensionBool is_valid = 0;745GDExtensionVariantType type = native_info->get_property_type_func(instance, (GDExtensionConstStringNamePtr)&p_name, &is_valid);746if (r_is_valid) {747*r_is_valid = is_valid != 0;748}749return Variant::Type(type);750}751return Variant::NIL;752}753virtual void validate_property(PropertyInfo &p_property) const override {754if (native_info->validate_property_func) {755// GDExtension uses a StringName rather than a String for property name.756StringName prop_name = p_property.name;757GDExtensionPropertyInfo gdext_prop = {758(GDExtensionVariantType)p_property.type,759&prop_name,760&p_property.class_name,761(uint32_t)p_property.hint,762&p_property.hint_string,763p_property.usage,764};765if (native_info->validate_property_func(instance, &gdext_prop)) {766p_property.type = (Variant::Type)gdext_prop.type;767p_property.name = *reinterpret_cast<StringName *>(gdext_prop.name);768p_property.class_name = *reinterpret_cast<StringName *>(gdext_prop.class_name);769p_property.hint = (PropertyHint)gdext_prop.hint;770p_property.hint_string = *reinterpret_cast<String *>(gdext_prop.hint_string);771p_property.usage = gdext_prop.usage;772}773}774}775776virtual bool property_can_revert(const StringName &p_name) const override {777if (native_info->property_can_revert_func) {778return native_info->property_can_revert_func(instance, (GDExtensionConstStringNamePtr)&p_name);779}780return false;781}782virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const override {783if (native_info->property_get_revert_func) {784return native_info->property_get_revert_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&r_ret);785}786return false;787}788789virtual Object *get_owner() override {790if (native_info->get_owner_func) {791return (Object *)native_info->get_owner_func(instance);792}793return nullptr;794}795static void _add_property_with_state(GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value, void *p_userdata) {796List<Pair<StringName, Variant>> *state = (List<Pair<StringName, Variant>> *)p_userdata;797state->push_back(Pair<StringName, Variant>(*(const StringName *)p_name, *(const Variant *)p_value));798}799virtual void get_property_state(List<Pair<StringName, Variant>> &state) override {800if (native_info->get_property_state_func) {801native_info->get_property_state_func(instance, _add_property_with_state, &state);802return;803}804ScriptInstance::get_property_state(state);805}806807virtual void get_method_list(List<MethodInfo> *p_list) const override {808if (native_info->get_method_list_func) {809uint32_t mcount;810const GDExtensionMethodInfo *minfo = native_info->get_method_list_func(instance, &mcount);811for (uint32_t i = 0; i < mcount; i++) {812p_list->push_back(MethodInfo(minfo[i]));813}814if (native_info->free_method_list_func) {815native_info->free_method_list_func(instance, minfo, mcount);816#ifndef DISABLE_DEPRECATED817} else if (deprecated_native_info && deprecated_native_info->free_method_list_func) {818deprecated_native_info->free_method_list_func(instance, minfo);819#endif // DISABLE_DEPRECATED820}821}822}823virtual bool has_method(const StringName &p_method) const override {824if (native_info->has_method_func) {825return native_info->has_method_func(instance, (GDExtensionStringNamePtr)&p_method);826}827return false;828}829830virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override {831if (native_info->get_method_argument_count_func) {832GDExtensionBool is_valid = 0;833GDExtensionInt ret = native_info->get_method_argument_count_func(instance, (GDExtensionStringNamePtr)&p_method, &is_valid);834if (r_is_valid) {835*r_is_valid = is_valid != 0;836}837return ret;838}839// Fallback to default.840return ScriptInstance::get_method_argument_count(p_method, r_is_valid);841}842843virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override {844Variant ret;845if (native_info->call_func) {846GDExtensionCallError ce;847native_info->call_func(instance, (GDExtensionConstStringNamePtr)&p_method, (GDExtensionConstVariantPtr *)p_args, p_argcount, (GDExtensionVariantPtr)&ret, &ce);848r_error.error = Callable::CallError::Error(ce.error);849r_error.argument = ce.argument;850r_error.expected = ce.expected;851}852return ret;853}854855virtual void notification(int p_notification, bool p_reversed = false) override {856if (native_info->notification_func) {857native_info->notification_func(instance, p_notification, p_reversed);858#ifndef DISABLE_DEPRECATED859} else if (deprecated_native_info && deprecated_native_info->notification_func) {860deprecated_native_info->notification_func(instance, p_notification);861#endif // DISABLE_DEPRECATED862}863}864865virtual String to_string(bool *r_valid) override {866if (native_info->to_string_func) {867GDExtensionBool valid;868String ret;869native_info->to_string_func(instance, &valid, reinterpret_cast<GDExtensionStringPtr>(&ret));870if (r_valid) {871*r_valid = valid != 0;872}873return ret;874}875return String();876}877878virtual void refcount_incremented() override {879if (native_info->refcount_incremented_func) {880native_info->refcount_incremented_func(instance);881}882}883virtual bool refcount_decremented() override {884if (native_info->refcount_decremented_func) {885return native_info->refcount_decremented_func(instance);886}887return false;888}889890virtual Ref<Script> get_script() const override {891if (native_info->get_script_func) {892GDExtensionObjectPtr script = native_info->get_script_func(instance);893return Ref<Script>(reinterpret_cast<Script *>(script));894}895return Ref<Script>();896}897898virtual bool is_placeholder() const override {899if (native_info->is_placeholder_func) {900return native_info->is_placeholder_func(instance);901}902return false;903}904905virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) override {906if (native_info->set_fallback_func) {907bool ret = native_info->set_fallback_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionConstVariantPtr)&p_value);908if (r_valid) {909*r_valid = ret;910}911}912}913virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid) override {914Variant ret;915if (native_info->get_fallback_func) {916bool valid = native_info->get_fallback_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&ret);917if (r_valid) {918*r_valid = valid;919}920}921return ret;922}923924virtual ScriptLanguage *get_language() override {925if (native_info->get_language_func) {926GDExtensionScriptLanguagePtr lang = native_info->get_language_func(instance);927return reinterpret_cast<ScriptLanguage *>(lang);928}929return nullptr;930}931virtual ~ScriptInstanceExtension() {932if (native_info->free_func) {933native_info->free_func(instance);934}935#ifndef DISABLE_DEPRECATED936if (free_native_info) {937memfree(const_cast<GDExtensionScriptInstanceInfo3 *>(native_info));938}939if (deprecated_native_info) {940memfree(deprecated_native_info);941}942#endif // DISABLE_DEPRECATED943}944945GODOT_GCC_WARNING_POP946};947948949