/**************************************************************************/ /* csharp_script.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 CSHARP_SCRIPT_H #define CSHARP_SCRIPT_H #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/script_language.h" #include "core/self_list.h" #include "mono_gc_handle.h" #include "mono_gd/gd_mono.h" #include "mono_gd/gd_mono_header.h" #include "mono_gd/gd_mono_internals.h" #ifdef TOOLS_ENABLED #include "editor/editor_plugin.h" #endif class CSharpScript; class CSharpInstance; class CSharpLanguage; #ifdef NO_SAFE_CAST template TScriptInstance *cast_script_instance(ScriptInstance *p_inst) { if (!p_inst) return NULL; return p_inst->get_language() == TScriptLanguage::get_singleton() ? static_cast(p_inst) : NULL; } #else template TScriptInstance *cast_script_instance(ScriptInstance *p_inst) { return dynamic_cast(p_inst); } #endif #define CAST_CSHARP_INSTANCE(m_inst) (cast_script_instance(m_inst)) class CSharpScript : public Script { GDCLASS(CSharpScript, Script); friend class CSharpInstance; friend class CSharpLanguage; friend struct CSharpScriptDepSort; bool tool; bool valid; bool reload_invalidated; bool builtin; GDMonoClass *base; GDMonoClass *native; GDMonoClass *script_class; Ref base_cache; // TODO what's this for? Set instances; #ifdef GD_MONO_HOT_RELOAD struct StateBackup { // TODO // Replace with buffer containing the serialized state of managed scripts. // Keep variant state backup to use only with script instance placeholders. List> properties; }; Set pending_reload_instances; Map pending_reload_state; StringName tied_class_name_for_reload; StringName tied_class_namespace_for_reload; #endif String source; StringName name; SelfList script_list; struct Argument { String name; Variant::Type type; }; Map> _signals; bool signals_invalidated; #ifdef TOOLS_ENABLED List exported_members_cache; // members_cache Map exported_members_defval_cache; // member_default_values_cache Set placeholders; bool source_changed_cache; bool placeholder_fallback_enabled; bool exports_invalidated; void _update_exports_values(Map &values, List &propnames); void _update_member_info_no_exports(); virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); #endif #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED) Set exported_members_names; #endif OrderedHashMap member_info; void _clear(); void load_script_signals(GDMonoClass *p_class, GDMonoClass *p_native_class); bool _get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Vector ¶ms); bool _update_exports(PlaceHolderScriptInstance *p_instance_to_update = nullptr); bool _get_member_export(IMonoClassMember *p_member, bool p_inspect_export, PropertyInfo &r_prop_info, bool &r_exported); #ifdef TOOLS_ENABLED static int _try_get_member_export_hint(IMonoClassMember *p_member, ManagedType p_type, Variant::Type p_variant_type, bool p_allow_generics, PropertyHint &r_hint, String &r_hint_string); #endif CSharpInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error); Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error); // Do not use unless you know what you are doing friend void GDMonoInternals::tie_managed_to_unmanaged(MonoObject *, Object *); static Ref create_for_managed_type(GDMonoClass *p_class, GDMonoClass *p_native); static void initialize_for_managed_type(Ref p_script, GDMonoClass *p_class, GDMonoClass *p_native); protected: static void _bind_methods(); Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); virtual void _resource_path_changed(); bool _get(const StringName &p_name, Variant &r_ret) const; bool _set(const StringName &p_name, const Variant &p_value); void _get_property_list(List *p_properties) const; public: virtual bool can_instance() const; virtual StringName get_instance_base_type() const; virtual ScriptInstance *instance_create(Object *p_this); virtual PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this); virtual bool instance_has(const Object *p_this) const; virtual bool has_source_code() const; virtual String get_source_code() const; virtual void set_source_code(const String &p_code); virtual Error reload(bool p_keep_state = false); virtual bool has_script_signal(const StringName &p_signal) const; virtual void get_script_signal_list(List *r_signals) const; virtual bool get_property_default_value(const StringName &p_property, Variant &r_value) const; virtual void get_script_property_list(List *p_list) const; virtual void update_exports(); virtual void get_members(Set *p_members); virtual bool is_tool() const { return tool; } virtual bool is_valid() const { return valid; } bool inherits_script(const Ref