2022-03-26 15:48:43 +00:00
|
|
|
/**************************************************************************/
|
|
|
|
/* script_language_extension.h */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/**************************************************************************/
|
|
|
|
/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
|
|
|
|
/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/**************************************************************************/
|
|
|
|
|
|
|
|
#ifndef SCRIPT_LANGUAGE_EXTENSION_H
|
|
|
|
#define SCRIPT_LANGUAGE_EXTENSION_H
|
|
|
|
|
|
|
|
#include "core/extension/ext_wrappers.gen.inc"
|
|
|
|
#include "core/object/gdvirtual.gen.inc"
|
|
|
|
#include "core/object/script_language.h"
|
|
|
|
#include "core/variant/native_ptr.h"
|
|
|
|
#include "core/variant/typed_array.h"
|
|
|
|
|
|
|
|
class ScriptExtension : public Script {
|
|
|
|
GDCLASS(ScriptExtension, Script)
|
|
|
|
|
|
|
|
protected:
|
|
|
|
EXBIND0R(bool, editor_can_reload_from_file)
|
|
|
|
|
2022-12-07 11:11:28 +00:00
|
|
|
GDVIRTUAL1(_placeholder_erased, GDExtensionPtr<void>)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override {
|
|
|
|
GDVIRTUAL_CALL(_placeholder_erased, p_placeholder);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
EXBIND0RC(bool, can_instantiate)
|
|
|
|
EXBIND0RC(Ref<Script>, get_base_script)
|
2023-01-19 18:12:25 +00:00
|
|
|
EXBIND0RC(StringName, get_global_name)
|
2022-03-26 15:48:43 +00:00
|
|
|
EXBIND1RC(bool, inherits_script, const Ref<Script> &)
|
|
|
|
EXBIND0RC(StringName, get_instance_base_type)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL1RC_REQUIRED(GDExtensionPtr<void>, _instance_create, Object *)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual ScriptInstance *instance_create(Object *p_this) override {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionPtr<void> ret = nullptr;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_instance_create, p_this, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
return reinterpret_cast<ScriptInstance *>(ret.operator void *());
|
|
|
|
}
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL1RC_REQUIRED(GDExtensionPtr<void>, _placeholder_instance_create, Object *)
|
2022-03-26 15:48:43 +00:00
|
|
|
PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionPtr<void> ret = nullptr;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_placeholder_instance_create, p_this, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
return reinterpret_cast<PlaceHolderScriptInstance *>(ret.operator void *());
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND1RC(bool, instance_has, const Object *)
|
|
|
|
EXBIND0RC(bool, has_source_code)
|
|
|
|
EXBIND0RC(String, get_source_code)
|
|
|
|
EXBIND1(set_source_code, const String &)
|
|
|
|
EXBIND1R(Error, reload, bool)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_documentation)
|
2023-08-24 10:49:20 +00:00
|
|
|
GDVIRTUAL0RC(String, _get_class_icon_path)
|
2022-03-26 15:48:43 +00:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
virtual Vector<DocData::ClassDoc> get_documentation() const override {
|
|
|
|
TypedArray<Dictionary> doc;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_documentation, doc);
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
Vector<DocData::ClassDoc> class_doc;
|
2022-10-10 19:58:25 +00:00
|
|
|
for (int i = 0; i < doc.size(); i++) {
|
|
|
|
class_doc.append(DocData::ClassDoc::from_dict(doc[i]));
|
|
|
|
}
|
|
|
|
|
2022-03-26 15:48:43 +00:00
|
|
|
return class_doc;
|
|
|
|
}
|
2023-08-24 10:49:20 +00:00
|
|
|
|
|
|
|
virtual String get_class_icon_path() const override {
|
|
|
|
String ret;
|
|
|
|
GDVIRTUAL_CALL(_get_class_icon_path, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2022-03-26 15:48:43 +00:00
|
|
|
#endif // TOOLS_ENABLED
|
|
|
|
|
|
|
|
EXBIND1RC(bool, has_method, const StringName &)
|
2023-10-04 04:54:03 +00:00
|
|
|
EXBIND1RC(bool, has_static_method, const StringName &)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2024-01-28 14:16:09 +00:00
|
|
|
GDVIRTUAL1RC(Variant, _get_script_method_argument_count, const StringName &)
|
|
|
|
virtual int get_script_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override {
|
|
|
|
Variant ret;
|
|
|
|
if (GDVIRTUAL_CALL(_get_script_method_argument_count, p_method, ret) && ret.get_type() == Variant::INT) {
|
|
|
|
if (r_is_valid) {
|
|
|
|
*r_is_valid = true;
|
|
|
|
}
|
|
|
|
return ret.operator int();
|
|
|
|
}
|
|
|
|
// Fallback to default.
|
|
|
|
return Script::get_script_method_argument_count(p_method, r_is_valid);
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL1RC_REQUIRED(Dictionary, _get_method_info, const StringName &)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual MethodInfo get_method_info(const StringName &p_method) const override {
|
|
|
|
Dictionary mi;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_method_info, p_method, mi);
|
2022-03-26 15:48:43 +00:00
|
|
|
return MethodInfo::from_dict(mi);
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND0RC(bool, is_tool)
|
|
|
|
EXBIND0RC(bool, is_valid)
|
|
|
|
|
2023-05-23 16:25:34 +00:00
|
|
|
virtual bool is_abstract() const override {
|
|
|
|
bool abst;
|
|
|
|
return GDVIRTUAL_CALL(_is_abstract, abst) && abst;
|
|
|
|
}
|
|
|
|
GDVIRTUAL0RC(bool, _is_abstract)
|
|
|
|
|
2022-03-26 15:48:43 +00:00
|
|
|
EXBIND0RC(ScriptLanguage *, get_language)
|
|
|
|
EXBIND1RC(bool, has_script_signal, const StringName &)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_signal_list)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual void get_script_signal_list(List<MethodInfo> *r_signals) const override {
|
|
|
|
TypedArray<Dictionary> sl;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_script_signal_list, sl);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < sl.size(); i++) {
|
|
|
|
r_signals->push_back(MethodInfo::from_dict(sl[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL1RC_REQUIRED(bool, _has_property_default_value, const StringName &)
|
|
|
|
GDVIRTUAL1RC_REQUIRED(Variant, _get_property_default_value, const StringName &)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const override {
|
|
|
|
bool has_dv = false;
|
2024-06-18 15:07:35 +00:00
|
|
|
if (!GDVIRTUAL_CALL(_has_property_default_value, p_property, has_dv) || !has_dv) {
|
2022-03-26 15:48:43 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
Variant ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_property_default_value, p_property, ret);
|
2023-01-07 03:49:20 +00:00
|
|
|
r_value = ret;
|
|
|
|
return true;
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND0(update_exports)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_method_list)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual void get_script_method_list(List<MethodInfo> *r_methods) const override {
|
|
|
|
TypedArray<Dictionary> sl;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_script_method_list, sl);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < sl.size(); i++) {
|
|
|
|
r_methods->push_back(MethodInfo::from_dict(sl[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_script_property_list)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual void get_script_property_list(List<PropertyInfo> *r_propertys) const override {
|
|
|
|
TypedArray<Dictionary> sl;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_script_property_list, sl);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < sl.size(); i++) {
|
|
|
|
r_propertys->push_back(PropertyInfo::from_dict(sl[i]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND1RC(int, get_member_line, const StringName &)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Dictionary, _get_constants)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2022-05-13 13:04:37 +00:00
|
|
|
virtual void get_constants(HashMap<StringName, Variant> *p_constants) override {
|
2022-03-26 15:48:43 +00:00
|
|
|
Dictionary constants;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_constants, constants);
|
2022-03-26 15:48:43 +00:00
|
|
|
List<Variant> keys;
|
|
|
|
constants.get_key_list(&keys);
|
|
|
|
for (const Variant &K : keys) {
|
|
|
|
p_constants->insert(K, constants[K]);
|
|
|
|
}
|
|
|
|
}
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(TypedArray<StringName>, _get_members)
|
2022-05-19 15:00:06 +00:00
|
|
|
virtual void get_members(HashSet<StringName> *p_members) override {
|
2022-03-26 15:48:43 +00:00
|
|
|
TypedArray<StringName> members;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_members, members);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < members.size(); i++) {
|
|
|
|
p_members->insert(members[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND0RC(bool, is_placeholder_fallback_enabled)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Variant, _get_rpc_config)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2024-08-24 05:58:54 +00:00
|
|
|
virtual Variant get_rpc_config() const override {
|
2022-07-12 21:12:42 +00:00
|
|
|
Variant ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_rpc_config, ret);
|
2022-07-12 21:12:42 +00:00
|
|
|
return ret;
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ScriptExtension() {}
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef ScriptLanguage::ProfilingInfo ScriptLanguageExtensionProfilingInfo;
|
|
|
|
|
|
|
|
GDVIRTUAL_NATIVE_PTR(ScriptLanguageExtensionProfilingInfo)
|
|
|
|
|
|
|
|
class ScriptLanguageExtension : public ScriptLanguage {
|
|
|
|
GDCLASS(ScriptLanguageExtension, ScriptLanguage)
|
|
|
|
protected:
|
|
|
|
static void _bind_methods();
|
|
|
|
|
|
|
|
public:
|
|
|
|
EXBIND0RC(String, get_name)
|
|
|
|
|
|
|
|
EXBIND0(init)
|
|
|
|
EXBIND0RC(String, get_type)
|
|
|
|
EXBIND0RC(String, get_extension)
|
|
|
|
EXBIND0(finish)
|
|
|
|
|
|
|
|
/* EDITOR FUNCTIONS */
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_reserved_words)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual void get_reserved_words(List<String> *p_words) const override {
|
|
|
|
Vector<String> ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_reserved_words, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
|
|
p_words->push_back(ret[i]);
|
|
|
|
}
|
|
|
|
}
|
2024-01-09 01:36:19 +00:00
|
|
|
EXBIND1RC(bool, is_control_flow_keyword, const String &)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_comment_delimiters)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual void get_comment_delimiters(List<String> *p_words) const override {
|
|
|
|
Vector<String> ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_comment_delimiters, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
|
|
p_words->push_back(ret[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-02-05 09:01:01 +00:00
|
|
|
GDVIRTUAL0RC(Vector<String>, _get_doc_comment_delimiters)
|
|
|
|
|
|
|
|
virtual void get_doc_comment_delimiters(List<String> *p_words) const override {
|
|
|
|
Vector<String> ret;
|
|
|
|
GDVIRTUAL_CALL(_get_doc_comment_delimiters, ret);
|
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
|
|
p_words->push_back(ret[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Vector<String>, _get_string_delimiters)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual void get_string_delimiters(List<String> *p_words) const override {
|
|
|
|
Vector<String> ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_string_delimiters, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
|
|
p_words->push_back(ret[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND3RC(Ref<Script>, make_template, const String &, const String &, const String &)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL1RC_REQUIRED(TypedArray<Dictionary>, _get_built_in_templates, StringName)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2021-08-01 19:47:20 +00:00
|
|
|
virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override {
|
2022-03-26 15:48:43 +00:00
|
|
|
TypedArray<Dictionary> ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_built_in_templates, p_object, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
Vector<ScriptTemplate> stret;
|
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
|
|
Dictionary d = ret[i];
|
|
|
|
ScriptTemplate st;
|
|
|
|
ERR_CONTINUE(!d.has("inherit"));
|
|
|
|
st.inherit = d["inherit"];
|
|
|
|
ERR_CONTINUE(!d.has("name"));
|
|
|
|
st.name = d["name"];
|
|
|
|
ERR_CONTINUE(!d.has("description"));
|
|
|
|
st.description = d["description"];
|
|
|
|
ERR_CONTINUE(!d.has("content"));
|
|
|
|
st.content = d["content"];
|
|
|
|
ERR_CONTINUE(!d.has("id"));
|
|
|
|
st.id = d["id"];
|
|
|
|
ERR_CONTINUE(!d.has("origin"));
|
|
|
|
st.origin = TemplateLocation(int(d["origin"]));
|
|
|
|
stret.push_back(st);
|
|
|
|
}
|
|
|
|
return stret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND0R(bool, is_using_templates)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL6RC_REQUIRED(Dictionary, _validate, const String &, const String &, bool, bool, bool, bool)
|
2022-05-19 15:00:06 +00:00
|
|
|
virtual bool validate(const String &p_script, const String &p_path = "", List<String> *r_functions = nullptr, List<ScriptError> *r_errors = nullptr, List<Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override {
|
2022-03-26 15:48:43 +00:00
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_validate, p_script, p_path, r_functions != nullptr, r_errors != nullptr, r_warnings != nullptr, r_safe_lines != nullptr, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (!ret.has("valid")) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if (r_functions != nullptr && ret.has("functions")) {
|
|
|
|
Vector<String> functions = ret["functions"];
|
|
|
|
for (int i = 0; i < functions.size(); i++) {
|
|
|
|
r_functions->push_back(functions[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r_errors != nullptr && ret.has("errors")) {
|
|
|
|
Array errors = ret["errors"];
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &error : errors) {
|
|
|
|
Dictionary err = error;
|
2022-03-26 15:48:43 +00:00
|
|
|
ERR_CONTINUE(!err.has("line"));
|
|
|
|
ERR_CONTINUE(!err.has("column"));
|
|
|
|
ERR_CONTINUE(!err.has("message"));
|
|
|
|
|
|
|
|
ScriptError serr;
|
2023-10-23 04:49:34 +00:00
|
|
|
if (err.has("path")) {
|
|
|
|
serr.path = err["path"];
|
|
|
|
}
|
2022-03-26 15:48:43 +00:00
|
|
|
serr.line = err["line"];
|
|
|
|
serr.column = err["column"];
|
|
|
|
serr.message = err["message"];
|
|
|
|
|
|
|
|
r_errors->push_back(serr);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r_warnings != nullptr && ret.has("warnings")) {
|
|
|
|
ERR_FAIL_COND_V(!ret.has("warnings"), false);
|
|
|
|
Array warnings = ret["warnings"];
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &warning : warnings) {
|
|
|
|
Dictionary warn = warning;
|
2022-03-26 15:48:43 +00:00
|
|
|
ERR_CONTINUE(!warn.has("start_line"));
|
|
|
|
ERR_CONTINUE(!warn.has("end_line"));
|
|
|
|
ERR_CONTINUE(!warn.has("leftmost_column"));
|
|
|
|
ERR_CONTINUE(!warn.has("rightmost_column"));
|
|
|
|
ERR_CONTINUE(!warn.has("code"));
|
|
|
|
ERR_CONTINUE(!warn.has("string_code"));
|
|
|
|
ERR_CONTINUE(!warn.has("message"));
|
|
|
|
|
|
|
|
Warning swarn;
|
|
|
|
swarn.start_line = warn["start_line"];
|
|
|
|
swarn.end_line = warn["end_line"];
|
|
|
|
swarn.leftmost_column = warn["leftmost_column"];
|
|
|
|
swarn.rightmost_column = warn["rightmost_column"];
|
|
|
|
swarn.code = warn["code"];
|
|
|
|
swarn.string_code = warn["string_code"];
|
|
|
|
swarn.message = warn["message"];
|
|
|
|
|
|
|
|
r_warnings->push_back(swarn);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (r_safe_lines != nullptr && ret.has("safe_lines")) {
|
|
|
|
PackedInt32Array safe_lines = ret["safe_lines"];
|
|
|
|
for (int i = 0; i < safe_lines.size(); i++) {
|
|
|
|
r_safe_lines->insert(safe_lines[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret["valid"];
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND1RC(String, validate_path, const String &)
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Object *, _create_script)
|
2022-03-26 15:48:43 +00:00
|
|
|
Script *create_script() const override {
|
|
|
|
Object *ret = nullptr;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_create_script, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
return Object::cast_to<Script>(ret);
|
|
|
|
}
|
2023-09-12 08:52:43 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
2022-03-26 15:48:43 +00:00
|
|
|
EXBIND0RC(bool, has_named_classes)
|
2023-09-12 08:52:43 +00:00
|
|
|
#endif
|
2022-03-26 15:48:43 +00:00
|
|
|
EXBIND0RC(bool, supports_builtin_mode)
|
|
|
|
EXBIND0RC(bool, supports_documentation)
|
|
|
|
EXBIND0RC(bool, can_inherit_from_file)
|
|
|
|
|
|
|
|
EXBIND2RC(int, find_function, const String &, const String &)
|
|
|
|
EXBIND3RC(String, make_function, const String &, const String &, const PackedStringArray &)
|
2024-02-04 18:08:41 +00:00
|
|
|
EXBIND0RC(bool, can_make_function)
|
2022-03-26 15:48:43 +00:00
|
|
|
EXBIND3R(Error, open_in_external_editor, const Ref<Script> &, int, int)
|
|
|
|
EXBIND0R(bool, overrides_external_editor)
|
2024-05-04 22:50:04 +00:00
|
|
|
|
|
|
|
GDVIRTUAL0RC(ScriptNameCasing, _preferred_file_name_casing);
|
|
|
|
|
|
|
|
virtual ScriptNameCasing preferred_file_name_casing() const override {
|
|
|
|
ScriptNameCasing ret;
|
|
|
|
if (GDVIRTUAL_CALL(_preferred_file_name_casing, ret)) {
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return ScriptNameCasing::SCRIPT_NAME_CASING_SNAKE_CASE;
|
|
|
|
}
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL3RC_REQUIRED(Dictionary, _complete_code, const String &, const String &, Object *)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual Error complete_code(const String &p_code, const String &p_path, Object *p_owner, List<CodeCompletionOption> *r_options, bool &r_force, String &r_call_hint) override {
|
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_complete_code, p_code, p_path, p_owner, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (!ret.has("result")) {
|
|
|
|
return ERR_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (r_options != nullptr && ret.has("options")) {
|
|
|
|
Array options = ret["options"];
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &var : options) {
|
|
|
|
Dictionary op = var;
|
2022-03-26 15:48:43 +00:00
|
|
|
CodeCompletionOption option;
|
|
|
|
ERR_CONTINUE(!op.has("kind"));
|
|
|
|
option.kind = CodeCompletionKind(int(op["kind"]));
|
|
|
|
ERR_CONTINUE(!op.has("display"));
|
|
|
|
option.display = op["display"];
|
|
|
|
ERR_CONTINUE(!op.has("insert_text"));
|
|
|
|
option.insert_text = op["insert_text"];
|
|
|
|
ERR_CONTINUE(!op.has("font_color"));
|
|
|
|
option.font_color = op["font_color"];
|
|
|
|
ERR_CONTINUE(!op.has("icon"));
|
|
|
|
option.icon = op["icon"];
|
|
|
|
ERR_CONTINUE(!op.has("default_value"));
|
|
|
|
option.default_value = op["default_value"];
|
2022-03-08 14:03:36 +00:00
|
|
|
ERR_CONTINUE(!op.has("location"));
|
|
|
|
option.location = op["location"];
|
2022-03-26 15:48:43 +00:00
|
|
|
if (op.has("matches")) {
|
|
|
|
PackedInt32Array matches = op["matches"];
|
|
|
|
ERR_CONTINUE(matches.size() & 1);
|
|
|
|
for (int j = 0; j < matches.size(); j += 2) {
|
|
|
|
option.matches.push_back(Pair<int, int>(matches[j], matches[j + 1]));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
r_options->push_back(option);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!ret.has("force"), ERR_UNAVAILABLE);
|
|
|
|
r_force = ret["force"];
|
|
|
|
ERR_FAIL_COND_V(!ret.has("call_hint"), ERR_UNAVAILABLE);
|
|
|
|
r_call_hint = ret["call_hint"];
|
|
|
|
ERR_FAIL_COND_V(!ret.has("result"), ERR_UNAVAILABLE);
|
|
|
|
Error result = Error(int(ret["result"]));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL4RC_REQUIRED(Dictionary, _lookup_code, const String &, const String &, const String &, Object *)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual Error lookup_code(const String &p_code, const String &p_symbol, const String &p_path, Object *p_owner, LookupResult &r_result) override {
|
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_lookup_code, p_code, p_symbol, p_path, p_owner, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (!ret.has("result")) {
|
|
|
|
return ERR_UNAVAILABLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
ERR_FAIL_COND_V(!ret.has("type"), ERR_UNAVAILABLE);
|
|
|
|
r_result.type = LookupResultType(int(ret["type"]));
|
|
|
|
ERR_FAIL_COND_V(!ret.has("script"), ERR_UNAVAILABLE);
|
|
|
|
r_result.script = ret["script"];
|
|
|
|
ERR_FAIL_COND_V(!ret.has("class_name"), ERR_UNAVAILABLE);
|
|
|
|
r_result.class_name = ret["class_name"];
|
|
|
|
ERR_FAIL_COND_V(!ret.has("class_path"), ERR_UNAVAILABLE);
|
|
|
|
r_result.class_path = ret["class_path"];
|
|
|
|
ERR_FAIL_COND_V(!ret.has("location"), ERR_UNAVAILABLE);
|
|
|
|
r_result.location = ret["location"];
|
|
|
|
|
|
|
|
Error result = Error(int(ret["result"]));
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL3RC_REQUIRED(String, _auto_indent_code, const String &, int, int)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override {
|
|
|
|
String ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_auto_indent_code, p_code, p_from_line, p_to_line, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
p_code = ret;
|
|
|
|
}
|
|
|
|
EXBIND2(add_global_constant, const StringName &, const Variant &)
|
|
|
|
EXBIND2(add_named_global_constant, const StringName &, const Variant &)
|
|
|
|
EXBIND1(remove_named_global_constant, const StringName &)
|
|
|
|
|
|
|
|
/* MULTITHREAD FUNCTIONS */
|
|
|
|
|
|
|
|
//some VMs need to be notified of thread creation/exiting to allocate a stack
|
|
|
|
EXBIND0(thread_enter)
|
|
|
|
EXBIND0(thread_exit)
|
|
|
|
|
|
|
|
EXBIND0RC(String, debug_get_error)
|
|
|
|
EXBIND0RC(int, debug_get_stack_level_count)
|
|
|
|
EXBIND1RC(int, debug_get_stack_level_line, int)
|
|
|
|
EXBIND1RC(String, debug_get_stack_level_function, int)
|
|
|
|
EXBIND1RC(String, debug_get_stack_level_source, int)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL3R_REQUIRED(Dictionary, _debug_get_stack_level_locals, int, int, int)
|
2022-03-26 15:48:43 +00:00
|
|
|
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 {
|
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_debug_get_stack_level_locals, p_level, p_max_subitems, p_max_depth, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (ret.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (p_locals != nullptr && ret.has("locals")) {
|
|
|
|
PackedStringArray strings = ret["locals"];
|
|
|
|
for (int i = 0; i < strings.size(); i++) {
|
|
|
|
p_locals->push_back(strings[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_values != nullptr && ret.has("values")) {
|
|
|
|
Array values = ret["values"];
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &value : values) {
|
|
|
|
p_values->push_back(value);
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL3R_REQUIRED(Dictionary, _debug_get_stack_level_members, int, int, int)
|
2022-03-26 15:48:43 +00:00
|
|
|
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 {
|
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_debug_get_stack_level_members, p_level, p_max_subitems, p_max_depth, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (ret.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (p_members != nullptr && ret.has("members")) {
|
|
|
|
PackedStringArray strings = ret["members"];
|
|
|
|
for (int i = 0; i < strings.size(); i++) {
|
|
|
|
p_members->push_back(strings[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_values != nullptr && ret.has("values")) {
|
|
|
|
Array values = ret["values"];
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &value : values) {
|
|
|
|
p_values->push_back(value);
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL1R_REQUIRED(GDExtensionPtr<void>, _debug_get_stack_level_instance, int)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual ScriptInstance *debug_get_stack_level_instance(int p_level) override {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionPtr<void> ret = nullptr;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_debug_get_stack_level_instance, p_level, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
return reinterpret_cast<ScriptInstance *>(ret.operator void *());
|
|
|
|
}
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL2R_REQUIRED(Dictionary, _debug_get_globals, int, int)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual void debug_get_globals(List<String> *p_globals, List<Variant> *p_values, int p_max_subitems = -1, int p_max_depth = -1) override {
|
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_debug_get_globals, p_max_subitems, p_max_depth, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (ret.size() == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (p_globals != nullptr && ret.has("globals")) {
|
|
|
|
PackedStringArray strings = ret["globals"];
|
|
|
|
for (int i = 0; i < strings.size(); i++) {
|
|
|
|
p_globals->push_back(strings[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (p_values != nullptr && ret.has("values")) {
|
|
|
|
Array values = ret["values"];
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &value : values) {
|
|
|
|
p_values->push_back(value);
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND4R(String, debug_parse_stack_level_expression, int, const String &, int, int)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0R_REQUIRED(TypedArray<Dictionary>, _debug_get_current_stack_info)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual Vector<StackInfo> debug_get_current_stack_info() override {
|
|
|
|
TypedArray<Dictionary> ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_debug_get_current_stack_info, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
Vector<StackInfo> sret;
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &var : ret) {
|
2022-03-26 15:48:43 +00:00
|
|
|
StackInfo si;
|
2023-12-24 12:44:21 +00:00
|
|
|
Dictionary d = var;
|
2022-03-26 15:48:43 +00:00
|
|
|
ERR_CONTINUE(!d.has("file"));
|
|
|
|
ERR_CONTINUE(!d.has("func"));
|
|
|
|
ERR_CONTINUE(!d.has("line"));
|
|
|
|
si.file = d["file"];
|
|
|
|
si.func = d["func"];
|
|
|
|
si.line = d["line"];
|
|
|
|
sret.push_back(si);
|
|
|
|
}
|
|
|
|
return sret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND0(reload_all_scripts)
|
2023-12-30 07:06:54 +00:00
|
|
|
EXBIND2(reload_scripts, const Array &, bool)
|
2022-03-26 15:48:43 +00:00
|
|
|
EXBIND2(reload_tool_script, const Ref<Script> &, bool)
|
|
|
|
/* LOADER FUNCTIONS */
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(PackedStringArray, _get_recognized_extensions)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual void get_recognized_extensions(List<String> *p_extensions) const override {
|
|
|
|
PackedStringArray ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_recognized_extensions, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
|
|
p_extensions->push_back(ret[i]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_public_functions)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual void get_public_functions(List<MethodInfo> *p_functions) const override {
|
|
|
|
TypedArray<Dictionary> ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_public_functions, ret);
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &var : ret) {
|
|
|
|
MethodInfo mi = MethodInfo::from_dict(var);
|
2022-03-26 15:48:43 +00:00
|
|
|
p_functions->push_back(mi);
|
|
|
|
}
|
|
|
|
}
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(Dictionary, _get_public_constants)
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual void get_public_constants(List<Pair<String, Variant>> *p_constants) const override {
|
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_public_constants, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (int i = 0; i < ret.size(); i++) {
|
|
|
|
Dictionary d = ret[i];
|
|
|
|
ERR_CONTINUE(!d.has("name"));
|
|
|
|
ERR_CONTINUE(!d.has("value"));
|
|
|
|
p_constants->push_back(Pair<String, Variant>(d["name"], d["value"]));
|
|
|
|
}
|
|
|
|
}
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL0RC_REQUIRED(TypedArray<Dictionary>, _get_public_annotations)
|
2022-07-04 15:56:34 +00:00
|
|
|
virtual void get_public_annotations(List<MethodInfo> *p_annotations) const override {
|
|
|
|
TypedArray<Dictionary> ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_public_annotations, ret);
|
2023-12-24 12:44:21 +00:00
|
|
|
for (const Variant &var : ret) {
|
|
|
|
MethodInfo mi = MethodInfo::from_dict(var);
|
2022-07-04 15:56:34 +00:00
|
|
|
p_annotations->push_back(mi);
|
|
|
|
}
|
|
|
|
}
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
EXBIND0(profiling_start)
|
|
|
|
EXBIND0(profiling_stop)
|
2023-03-05 12:37:11 +00:00
|
|
|
EXBIND1(profiling_set_save_native_calls, bool)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL2R_REQUIRED(int, _profiling_get_accumulated_data, GDExtensionPtr<ScriptLanguageExtensionProfilingInfo>, int)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override {
|
|
|
|
int ret = 0;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_profiling_get_accumulated_data, p_info_arr, p_info_max, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL2R_REQUIRED(int, _profiling_get_frame_data, GDExtensionPtr<ScriptLanguageExtensionProfilingInfo>, int)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override {
|
|
|
|
int ret = 0;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_profiling_get_frame_data, p_info_arr, p_info_max, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
EXBIND0(frame)
|
|
|
|
|
|
|
|
EXBIND1RC(bool, handles_global_class_type, const String &)
|
|
|
|
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL1RC_REQUIRED(Dictionary, _get_global_class_name, const String &)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const override {
|
|
|
|
Dictionary ret;
|
2024-06-18 15:07:35 +00:00
|
|
|
GDVIRTUAL_CALL(_get_global_class_name, p_path, ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (!ret.has("name")) {
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
if (r_base_type != nullptr && ret.has("base_type")) {
|
|
|
|
*r_base_type = ret["base_type"];
|
|
|
|
}
|
|
|
|
if (r_icon_path != nullptr && ret.has("icon_path")) {
|
|
|
|
*r_icon_path = ret["icon_path"];
|
|
|
|
}
|
|
|
|
return ret["name"];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
VARIANT_ENUM_CAST(ScriptLanguageExtension::LookupResultType)
|
|
|
|
VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionKind)
|
2022-03-08 14:03:36 +00:00
|
|
|
VARIANT_ENUM_CAST(ScriptLanguageExtension::CodeCompletionLocation)
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
class ScriptInstanceExtension : public ScriptInstance {
|
|
|
|
public:
|
2024-03-01 15:56:19 +00:00
|
|
|
const GDExtensionScriptInstanceInfo3 *native_info;
|
|
|
|
|
|
|
|
#ifndef DISABLE_DEPRECATED
|
2023-08-31 20:19:31 +00:00
|
|
|
bool free_native_info = false;
|
2024-03-01 15:56:19 +00:00
|
|
|
struct DeprecatedNativeInfo {
|
2023-09-25 20:46:59 +00:00
|
|
|
GDExtensionScriptInstanceNotification notification_func = nullptr;
|
2024-03-01 15:56:19 +00:00
|
|
|
GDExtensionScriptInstanceFreePropertyList free_property_list_func = nullptr;
|
|
|
|
GDExtensionScriptInstanceFreeMethodList free_method_list_func = nullptr;
|
|
|
|
};
|
|
|
|
DeprecatedNativeInfo *deprecated_native_info = nullptr;
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2023-06-24 01:07:22 +00:00
|
|
|
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionScriptInstanceDataPtr instance = nullptr;
|
2022-03-26 15:48:43 +00:00
|
|
|
|
|
|
|
// There should not be warnings on explicit casts.
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic push
|
|
|
|
#pragma GCC diagnostic ignored "-Wignored-qualifiers"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
virtual bool set(const StringName &p_name, const Variant &p_value) override {
|
|
|
|
if (native_info->set_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
return native_info->set_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionConstVariantPtr)&p_value);
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual bool get(const StringName &p_name, Variant &r_ret) const override {
|
|
|
|
if (native_info->get_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
return native_info->get_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&r_ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual void get_property_list(List<PropertyInfo> *p_list) const override {
|
|
|
|
if (native_info->get_property_list_func) {
|
|
|
|
uint32_t pcount;
|
2022-12-07 11:11:28 +00:00
|
|
|
const GDExtensionPropertyInfo *pinfo = native_info->get_property_list_func(instance, &pcount);
|
2022-07-31 08:07:48 +00:00
|
|
|
|
|
|
|
#ifdef TOOLS_ENABLED
|
2023-07-01 13:09:21 +00:00
|
|
|
if (pcount > 0) {
|
|
|
|
if (native_info->get_class_category_func) {
|
|
|
|
GDExtensionPropertyInfo gdext_class_category;
|
|
|
|
if (native_info->get_class_category_func(instance, &gdext_class_category)) {
|
|
|
|
p_list->push_back(PropertyInfo(gdext_class_category));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
Ref<Script> script = get_script();
|
|
|
|
if (script.is_valid()) {
|
|
|
|
p_list->push_back(script->get_class_category());
|
|
|
|
}
|
|
|
|
}
|
2022-07-31 08:07:48 +00:00
|
|
|
}
|
|
|
|
#endif // TOOLS_ENABLED
|
|
|
|
|
2022-03-26 15:48:43 +00:00
|
|
|
for (uint32_t i = 0; i < pcount; i++) {
|
2022-06-06 20:24:13 +00:00
|
|
|
p_list->push_back(PropertyInfo(pinfo[i]));
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
if (native_info->free_property_list_func) {
|
2024-03-01 15:56:19 +00:00
|
|
|
native_info->free_property_list_func(instance, pinfo, pcount);
|
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
} else if (deprecated_native_info && deprecated_native_info->free_property_list_func) {
|
|
|
|
deprecated_native_info->free_property_list_func(instance, pinfo);
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid = nullptr) const override {
|
2022-11-10 14:57:56 +00:00
|
|
|
if (native_info->get_property_type_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionBool is_valid = 0;
|
|
|
|
GDExtensionVariantType type = native_info->get_property_type_func(instance, (GDExtensionConstStringNamePtr)&p_name, &is_valid);
|
2022-11-10 14:57:56 +00:00
|
|
|
if (r_is_valid) {
|
|
|
|
*r_is_valid = is_valid != 0;
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
2022-11-10 14:57:56 +00:00
|
|
|
return Variant::Type(type);
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
2022-11-10 14:57:56 +00:00
|
|
|
return Variant::NIL;
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
2023-04-07 12:01:57 +00:00
|
|
|
virtual void validate_property(PropertyInfo &p_property) const override {
|
2023-09-02 22:26:36 +00:00
|
|
|
if (native_info->validate_property_func) {
|
2023-09-09 18:05:16 +00:00
|
|
|
// GDExtension uses a StringName rather than a String for property name.
|
|
|
|
StringName prop_name = p_property.name;
|
2023-09-02 22:26:36 +00:00
|
|
|
GDExtensionPropertyInfo gdext_prop = {
|
|
|
|
(GDExtensionVariantType)p_property.type,
|
2023-09-09 18:05:16 +00:00
|
|
|
&prop_name,
|
2023-09-02 22:26:36 +00:00
|
|
|
&p_property.class_name,
|
|
|
|
(uint32_t)p_property.hint,
|
|
|
|
&p_property.hint_string,
|
|
|
|
p_property.usage,
|
|
|
|
};
|
|
|
|
if (native_info->validate_property_func(instance, &gdext_prop)) {
|
|
|
|
p_property.type = (Variant::Type)gdext_prop.type;
|
|
|
|
p_property.name = *reinterpret_cast<StringName *>(gdext_prop.name);
|
|
|
|
p_property.class_name = *reinterpret_cast<StringName *>(gdext_prop.class_name);
|
|
|
|
p_property.hint = (PropertyHint)gdext_prop.hint;
|
|
|
|
p_property.hint_string = *reinterpret_cast<String *>(gdext_prop.hint_string);
|
|
|
|
p_property.usage = gdext_prop.usage;
|
|
|
|
}
|
|
|
|
}
|
2023-04-07 12:01:57 +00:00
|
|
|
}
|
2022-03-26 15:48:43 +00:00
|
|
|
|
2022-08-12 18:43:14 +00:00
|
|
|
virtual bool property_can_revert(const StringName &p_name) const override {
|
|
|
|
if (native_info->property_can_revert_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
return native_info->property_can_revert_func(instance, (GDExtensionConstStringNamePtr)&p_name);
|
2022-08-12 18:43:14 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
virtual bool property_get_revert(const StringName &p_name, Variant &r_ret) const override {
|
|
|
|
if (native_info->property_get_revert_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
return native_info->property_get_revert_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&r_ret);
|
2022-08-12 18:43:14 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual Object *get_owner() override {
|
|
|
|
if (native_info->get_owner_func) {
|
|
|
|
return (Object *)native_info->get_owner_func(instance);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
2022-12-07 11:11:28 +00:00
|
|
|
static void _add_property_with_state(GDExtensionConstStringNamePtr p_name, GDExtensionConstVariantPtr p_value, void *p_userdata) {
|
2022-03-26 15:48:43 +00:00
|
|
|
List<Pair<StringName, Variant>> *state = (List<Pair<StringName, Variant>> *)p_userdata;
|
|
|
|
state->push_back(Pair<StringName, Variant>(*(const StringName *)p_name, *(const Variant *)p_value));
|
|
|
|
}
|
|
|
|
virtual void get_property_state(List<Pair<StringName, Variant>> &state) override {
|
|
|
|
if (native_info->get_property_state_func) {
|
|
|
|
native_info->get_property_state_func(instance, _add_property_with_state, &state);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void get_method_list(List<MethodInfo> *p_list) const override {
|
|
|
|
if (native_info->get_method_list_func) {
|
|
|
|
uint32_t mcount;
|
2022-12-07 11:11:28 +00:00
|
|
|
const GDExtensionMethodInfo *minfo = native_info->get_method_list_func(instance, &mcount);
|
2022-03-26 15:48:43 +00:00
|
|
|
for (uint32_t i = 0; i < mcount; i++) {
|
2022-10-23 08:43:09 +00:00
|
|
|
p_list->push_back(MethodInfo(minfo[i]));
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
if (native_info->free_method_list_func) {
|
2024-03-01 15:56:19 +00:00
|
|
|
native_info->free_method_list_func(instance, minfo, mcount);
|
|
|
|
#ifndef DISABLE_DEPRECATED
|
|
|
|
} else if (deprecated_native_info && deprecated_native_info->free_method_list_func) {
|
|
|
|
deprecated_native_info->free_method_list_func(instance, minfo);
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual bool has_method(const StringName &p_method) const override {
|
|
|
|
if (native_info->has_method_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
return native_info->has_method_func(instance, (GDExtensionStringNamePtr)&p_method);
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-01-28 14:16:09 +00:00
|
|
|
virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override {
|
2024-01-30 11:00:36 +00:00
|
|
|
if (native_info->get_method_argument_count_func) {
|
|
|
|
GDExtensionBool is_valid = 0;
|
|
|
|
GDExtensionInt ret = native_info->get_method_argument_count_func(instance, (GDExtensionStringNamePtr)&p_method, &is_valid);
|
|
|
|
if (r_is_valid) {
|
|
|
|
*r_is_valid = is_valid != 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
2024-01-28 14:16:09 +00:00
|
|
|
// Fallback to default.
|
|
|
|
return ScriptInstance::get_method_argument_count(p_method, r_is_valid);
|
|
|
|
}
|
|
|
|
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override {
|
|
|
|
Variant ret;
|
|
|
|
if (native_info->call_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionCallError ce;
|
|
|
|
native_info->call_func(instance, (GDExtensionConstStringNamePtr)&p_method, (GDExtensionConstVariantPtr *)p_args, p_argcount, (GDExtensionVariantPtr)&ret, &ce);
|
2022-03-26 15:48:43 +00:00
|
|
|
r_error.error = Callable::CallError::Error(ce.error);
|
|
|
|
r_error.argument = ce.argument;
|
|
|
|
r_error.expected = ce.expected;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2023-06-24 01:07:22 +00:00
|
|
|
virtual void notification(int p_notification, bool p_reversed = false) override {
|
2022-03-26 15:48:43 +00:00
|
|
|
if (native_info->notification_func) {
|
2023-06-24 01:07:22 +00:00
|
|
|
native_info->notification_func(instance, p_notification, p_reversed);
|
|
|
|
#ifndef DISABLE_DEPRECATED
|
2024-03-01 15:56:19 +00:00
|
|
|
} else if (deprecated_native_info && deprecated_native_info->notification_func) {
|
|
|
|
deprecated_native_info->notification_func(instance, p_notification);
|
2023-06-24 01:07:22 +00:00
|
|
|
#endif // DISABLE_DEPRECATED
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
}
|
2023-06-24 01:07:22 +00:00
|
|
|
|
2022-03-26 15:48:43 +00:00
|
|
|
virtual String to_string(bool *r_valid) override {
|
|
|
|
if (native_info->to_string_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionBool valid;
|
2022-10-23 08:43:09 +00:00
|
|
|
String ret;
|
2022-12-07 11:11:28 +00:00
|
|
|
native_info->to_string_func(instance, &valid, reinterpret_cast<GDExtensionStringPtr>(&ret));
|
2022-03-26 15:48:43 +00:00
|
|
|
if (r_valid) {
|
|
|
|
*r_valid = valid != 0;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
return String();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void refcount_incremented() override {
|
|
|
|
if (native_info->refcount_incremented_func) {
|
|
|
|
native_info->refcount_incremented_func(instance);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual bool refcount_decremented() override {
|
|
|
|
if (native_info->refcount_decremented_func) {
|
|
|
|
return native_info->refcount_decremented_func(instance);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual Ref<Script> get_script() const override {
|
|
|
|
if (native_info->get_script_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionObjectPtr script = native_info->get_script_func(instance);
|
2022-03-26 15:48:43 +00:00
|
|
|
return Ref<Script>(reinterpret_cast<Script *>(script));
|
|
|
|
}
|
|
|
|
return Ref<Script>();
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual bool is_placeholder() const override {
|
|
|
|
if (native_info->is_placeholder_func) {
|
|
|
|
return native_info->is_placeholder_func(instance);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void property_set_fallback(const StringName &p_name, const Variant &p_value, bool *r_valid) override {
|
|
|
|
if (native_info->set_fallback_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
bool ret = native_info->set_fallback_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionConstVariantPtr)&p_value);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (r_valid) {
|
|
|
|
*r_valid = ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
virtual Variant property_get_fallback(const StringName &p_name, bool *r_valid) override {
|
|
|
|
Variant ret;
|
|
|
|
if (native_info->get_fallback_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
bool valid = native_info->get_fallback_func(instance, (GDExtensionConstStringNamePtr)&p_name, (GDExtensionVariantPtr)&ret);
|
2022-03-26 15:48:43 +00:00
|
|
|
if (r_valid) {
|
|
|
|
*r_valid = valid;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual ScriptLanguage *get_language() override {
|
|
|
|
if (native_info->get_language_func) {
|
2022-12-07 11:11:28 +00:00
|
|
|
GDExtensionScriptLanguagePtr lang = native_info->get_language_func(instance);
|
2022-03-26 15:48:43 +00:00
|
|
|
return reinterpret_cast<ScriptLanguage *>(lang);
|
|
|
|
}
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
virtual ~ScriptInstanceExtension() {
|
|
|
|
if (native_info->free_func) {
|
|
|
|
native_info->free_func(instance);
|
|
|
|
}
|
2024-03-01 15:56:19 +00:00
|
|
|
#ifndef DISABLE_DEPRECATED
|
2023-08-31 20:19:31 +00:00
|
|
|
if (free_native_info) {
|
2024-03-01 15:56:19 +00:00
|
|
|
memfree(const_cast<GDExtensionScriptInstanceInfo3 *>(native_info));
|
2023-08-31 20:19:31 +00:00
|
|
|
}
|
2024-03-01 15:56:19 +00:00
|
|
|
if (deprecated_native_info) {
|
|
|
|
memfree(deprecated_native_info);
|
|
|
|
}
|
|
|
|
#endif // DISABLE_DEPRECATED
|
2022-03-26 15:48:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#if defined(__GNUC__) && !defined(__clang__)
|
|
|
|
#pragma GCC diagnostic pop
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // SCRIPT_LANGUAGE_EXTENSION_H
|