/*************************************************************************/ /* csharp_script.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */ /* */ /* 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/doc_data.h" #include "core/io/resource_loader.h" #include "core/io/resource_saver.h" #include "core/object/script_language.h" #include "core/templates/self_list.h" #include "mono_gc_handle.h" #include "mono_gd/gd_mono.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 nullptr; } return p_inst->get_language() == TScriptLanguage::get_singleton() ? static_cast(p_inst) : nullptr; } #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; bool tool = false; bool valid = false; bool reload_invalidated = false; Ref base_script; HashSet 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; Dictionary event_signals; }; HashSet pending_reload_instances; RBMap pending_reload_state; bool was_tool_before_reload = false; HashSet pending_replace_placeholders; #endif String source; SelfList script_list = this; Dictionary rpc_config; struct EventSignalInfo { StringName name; // MethodInfo stores a string... MethodInfo method_info; }; struct CSharpMethodInfo { StringName name; // MethodInfo stores a string... MethodInfo method_info; }; Vector event_signals; Vector methods; #ifdef TOOLS_ENABLED List exported_members_cache; // members_cache HashMap exported_members_defval_cache; // member_default_values_cache HashSet placeholders; bool source_changed_cache = false; bool placeholder_fallback_enabled = false; bool exports_invalidated = true; void _update_exports_values(HashMap &values, List &propnames); void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override; #endif #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED) HashSet exported_members_names; #endif HashMap member_info; void _clear(); bool _update_exports(PlaceHolderScriptInstance *p_instance_to_update = nullptr); CSharpInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error); Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error); // Do not use unless you know what you are doing static void update_script_class_info(Ref p_script); protected: static void _bind_methods(); 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: static void reload_registered_script(Ref p_script); bool can_instantiate() const override; StringName get_instance_base_type() const override; ScriptInstance *instance_create(Object *p_this) override; PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override; bool instance_has(const Object *p_this) const override; bool has_source_code() const override; String get_source_code() const override; void set_source_code(const String &p_code) override; #ifdef TOOLS_ENABLED virtual Vector get_documentation() const override { // TODO Vector docs; return docs; } #endif // TOOLS_ENABLED Error reload(bool p_keep_state = false) override; bool has_script_signal(const StringName &p_signal) const override; void get_script_signal_list(List *r_signals) const override; Vector get_script_event_signals() const; bool get_property_default_value(const StringName &p_property, Variant &r_value) const override; void get_script_property_list(List *r_list) const override; void update_exports() override; void get_members(HashSet *p_members) override; bool is_tool() const override { return tool; } bool is_valid() const override { return valid; } bool inherits_script(const Ref