/*************************************************************************/ /* csharp_script.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ /* https://godotengine.org */ /*************************************************************************/ /* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */ /* Copyright (c) 2014-2018 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 "io/resource_loader.h" #include "io/resource_saver.h" #include "script_language.h" #include "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" class CSharpScript; class CSharpInstance; class CSharpLanguage; #ifdef NO_SAFE_CAST template TScriptInstance *cast_script_instance(ScriptInstance *p_inst) { 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 class CSharpScriptDepSort; bool tool; bool valid; bool builtin; GDMonoClass *base; GDMonoClass *native; GDMonoClass *script_class; Ref base_cache; // TODO what's this for? Set instances; 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 exports_invalidated; void _update_exports_values(Map &values, List &propnames); virtual void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder); #endif #ifdef DEBUG_ENABLED Map > > pending_reload_state; #endif Map 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(); #ifdef TOOLS_ENABLED bool _get_member_export(GDMonoClass *p_class, GDMonoClassMember *p_member, PropertyInfo &r_prop_info, bool &r_exported); #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); 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; /* TODO */ 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 bool is_tool() const { return tool; } virtual Ref