csharp_script.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606
  1. /**************************************************************************/
  2. /* csharp_script.h */
  3. /**************************************************************************/
  4. /* This file is part of: */
  5. /* GODOT ENGINE */
  6. /* https://godotengine.org */
  7. /**************************************************************************/
  8. /* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
  9. /* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
  10. /* */
  11. /* Permission is hereby granted, free of charge, to any person obtaining */
  12. /* a copy of this software and associated documentation files (the */
  13. /* "Software"), to deal in the Software without restriction, including */
  14. /* without limitation the rights to use, copy, modify, merge, publish, */
  15. /* distribute, sublicense, and/or sell copies of the Software, and to */
  16. /* permit persons to whom the Software is furnished to do so, subject to */
  17. /* the following conditions: */
  18. /* */
  19. /* The above copyright notice and this permission notice shall be */
  20. /* included in all copies or substantial portions of the Software. */
  21. /* */
  22. /* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
  23. /* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
  24. /* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
  25. /* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
  26. /* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
  27. /* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
  28. /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
  29. /**************************************************************************/
  30. #ifndef CSHARP_SCRIPT_H
  31. #define CSHARP_SCRIPT_H
  32. #include "mono_gc_handle.h"
  33. #include "mono_gd/gd_mono.h"
  34. #include "core/doc_data.h"
  35. #include "core/io/resource_loader.h"
  36. #include "core/io/resource_saver.h"
  37. #include "core/object/script_language.h"
  38. #include "core/templates/self_list.h"
  39. #ifdef TOOLS_ENABLED
  40. #include "editor/plugins/editor_plugin.h"
  41. #endif
  42. class CSharpScript;
  43. class CSharpInstance;
  44. class CSharpLanguage;
  45. template <typename TScriptInstance, typename TScriptLanguage>
  46. TScriptInstance *cast_script_instance(ScriptInstance *p_inst) {
  47. return dynamic_cast<TScriptInstance *>(p_inst);
  48. }
  49. #define CAST_CSHARP_INSTANCE(m_inst) (cast_script_instance<CSharpInstance, CSharpLanguage>(m_inst))
  50. class CSharpScript : public Script {
  51. GDCLASS(CSharpScript, Script);
  52. friend class CSharpInstance;
  53. friend class CSharpLanguage;
  54. public:
  55. struct TypeInfo {
  56. /**
  57. * Name of the C# class.
  58. */
  59. String class_name;
  60. /**
  61. * Name of the native class this script derives from.
  62. */
  63. StringName native_base_name;
  64. /**
  65. * Path to the icon that will be used for this class by the editor.
  66. */
  67. String icon_path;
  68. /**
  69. * Script is marked as tool and runs in the editor.
  70. */
  71. bool is_tool = false;
  72. /**
  73. * Script is marked as global class and will be registered in the editor.
  74. * Registered classes can be created using certain editor dialogs and
  75. * can be referenced by name from other languages that support the feature.
  76. */
  77. bool is_global_class = false;
  78. /**
  79. * Script is declared abstract.
  80. */
  81. bool is_abstract = false;
  82. /**
  83. * The C# type that corresponds to this script is a constructed generic type.
  84. * E.g.: `Dictionary<int, string>`
  85. */
  86. bool is_constructed_generic_type = false;
  87. /**
  88. * The C# type that corresponds to this script is a generic type definition.
  89. * E.g.: `Dictionary<,>`
  90. */
  91. bool is_generic_type_definition = false;
  92. /**
  93. * The C# type that corresponds to this script contains generic type parameters,
  94. * regardless of whether the type parameters are bound or not.
  95. */
  96. bool is_generic() const {
  97. return is_constructed_generic_type || is_generic_type_definition;
  98. }
  99. /**
  100. * Check if the script can be instantiated.
  101. * C# types can't be instantiated if they are abstract or contain generic
  102. * type parameters, but a CSharpScript is still created for them.
  103. */
  104. bool can_instantiate() const {
  105. return !is_abstract && !is_generic_type_definition;
  106. }
  107. };
  108. private:
  109. /**
  110. * Contains the C# type information for this script.
  111. */
  112. TypeInfo type_info;
  113. /**
  114. * Scripts are valid when the corresponding C# class is found and used
  115. * to extract the script info using the [update_script_class_info] method.
  116. */
  117. bool valid = false;
  118. /**
  119. * Scripts extract info from the C# class in the reload methods but,
  120. * if the reload is not invalidated, then the current extracted info
  121. * is still valid and there's no need to reload again.
  122. */
  123. bool reload_invalidated = false;
  124. /**
  125. * Base script that this script derives from, or null if it derives from a
  126. * native Godot class.
  127. */
  128. Ref<CSharpScript> base_script;
  129. HashSet<Object *> instances;
  130. #ifdef GD_MONO_HOT_RELOAD
  131. struct StateBackup {
  132. // TODO
  133. // Replace with buffer containing the serialized state of managed scripts.
  134. // Keep variant state backup to use only with script instance placeholders.
  135. List<Pair<StringName, Variant>> properties;
  136. Dictionary event_signals;
  137. };
  138. HashSet<ObjectID> pending_reload_instances;
  139. RBMap<ObjectID, StateBackup> pending_reload_state;
  140. bool was_tool_before_reload = false;
  141. HashSet<ObjectID> pending_replace_placeholders;
  142. #endif
  143. /**
  144. * Script source code.
  145. */
  146. String source;
  147. SelfList<CSharpScript> script_list = this;
  148. Dictionary rpc_config;
  149. struct EventSignalInfo {
  150. StringName name; // MethodInfo stores a string...
  151. MethodInfo method_info;
  152. };
  153. struct CSharpMethodInfo {
  154. StringName name; // MethodInfo stores a string...
  155. MethodInfo method_info;
  156. };
  157. Vector<EventSignalInfo> event_signals;
  158. Vector<CSharpMethodInfo> methods;
  159. #ifdef TOOLS_ENABLED
  160. List<PropertyInfo> exported_members_cache; // members_cache
  161. HashMap<StringName, Variant> exported_members_defval_cache; // member_default_values_cache
  162. HashSet<PlaceHolderScriptInstance *> placeholders;
  163. bool source_changed_cache = false;
  164. bool placeholder_fallback_enabled = false;
  165. bool exports_invalidated = true;
  166. void _update_exports_values(HashMap<StringName, Variant> &values, List<PropertyInfo> &propnames);
  167. void _placeholder_erased(PlaceHolderScriptInstance *p_placeholder) override;
  168. #endif
  169. #if defined(TOOLS_ENABLED) || defined(DEBUG_ENABLED)
  170. HashSet<StringName> exported_members_names;
  171. #endif
  172. HashMap<StringName, PropertyInfo> member_info;
  173. void _clear();
  174. static void GD_CLR_STDCALL _add_property_info_list_callback(CSharpScript *p_script, const String *p_current_class_name, void *p_props, int32_t p_count);
  175. #ifdef TOOLS_ENABLED
  176. static void GD_CLR_STDCALL _add_property_default_values_callback(CSharpScript *p_script, void *p_def_vals, int32_t p_count);
  177. #endif
  178. bool _update_exports(PlaceHolderScriptInstance *p_instance_to_update = nullptr);
  179. CSharpInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_is_ref_counted, Callable::CallError &r_error);
  180. Variant _new(const Variant **p_args, int p_argcount, Callable::CallError &r_error);
  181. // Do not use unless you know what you are doing
  182. static void update_script_class_info(Ref<CSharpScript> p_script);
  183. void _get_script_signal_list(List<MethodInfo> *r_signals, bool p_include_base) const;
  184. protected:
  185. static void _bind_methods();
  186. bool _get(const StringName &p_name, Variant &r_ret) const;
  187. bool _set(const StringName &p_name, const Variant &p_value);
  188. void _get_property_list(List<PropertyInfo> *p_properties) const;
  189. public:
  190. static void reload_registered_script(Ref<CSharpScript> p_script);
  191. bool can_instantiate() const override;
  192. StringName get_instance_base_type() const override;
  193. ScriptInstance *instance_create(Object *p_this) override;
  194. PlaceHolderScriptInstance *placeholder_instance_create(Object *p_this) override;
  195. bool instance_has(const Object *p_this) const override;
  196. bool has_source_code() const override;
  197. String get_source_code() const override;
  198. void set_source_code(const String &p_code) override;
  199. #ifdef TOOLS_ENABLED
  200. virtual Vector<DocData::ClassDoc> get_documentation() const override {
  201. // TODO
  202. Vector<DocData::ClassDoc> docs;
  203. return docs;
  204. }
  205. virtual String get_class_icon_path() const override {
  206. return type_info.icon_path;
  207. }
  208. #endif // TOOLS_ENABLED
  209. Error reload(bool p_keep_state = false) override;
  210. bool has_script_signal(const StringName &p_signal) const override;
  211. void get_script_signal_list(List<MethodInfo> *r_signals) const override;
  212. bool get_property_default_value(const StringName &p_property, Variant &r_value) const override;
  213. void get_script_property_list(List<PropertyInfo> *r_list) const override;
  214. void update_exports() override;
  215. void get_members(HashSet<StringName> *p_members) override;
  216. bool is_tool() const override {
  217. return type_info.is_tool;
  218. }
  219. bool is_valid() const override {
  220. return valid;
  221. }
  222. bool is_abstract() const override {
  223. return type_info.is_abstract;
  224. }
  225. bool inherits_script(const Ref<Script> &p_script) const override;
  226. Ref<Script> get_base_script() const override;
  227. StringName get_global_name() const override;
  228. ScriptLanguage *get_language() const override;
  229. void get_script_method_list(List<MethodInfo> *p_list) const override;
  230. bool has_method(const StringName &p_method) const override;
  231. virtual int get_script_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override;
  232. MethodInfo get_method_info(const StringName &p_method) const override;
  233. Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
  234. int get_member_line(const StringName &p_member) const override;
  235. Variant get_rpc_config() const override;
  236. #ifdef TOOLS_ENABLED
  237. bool is_placeholder_fallback_enabled() const override {
  238. return placeholder_fallback_enabled;
  239. }
  240. #endif
  241. Error load_source_code(const String &p_path);
  242. CSharpScript();
  243. ~CSharpScript();
  244. };
  245. class CSharpInstance : public ScriptInstance {
  246. friend class CSharpScript;
  247. friend class CSharpLanguage;
  248. Object *owner = nullptr;
  249. bool base_ref_counted = false;
  250. bool ref_dying = false;
  251. bool unsafe_referenced = false;
  252. bool predelete_notified = false;
  253. bool destructing_script_instance = false;
  254. Ref<CSharpScript> script;
  255. MonoGCHandleData gchandle;
  256. List<Callable> connected_event_signals;
  257. bool _reference_owner_unsafe();
  258. /*
  259. * If true is returned, the caller must memdelete the script instance's owner.
  260. */
  261. bool _unreference_owner_unsafe();
  262. /*
  263. * If false is returned, the caller must destroy the script instance by removing it from its owner.
  264. */
  265. bool _internal_new_managed();
  266. // Do not use unless you know what you are doing
  267. static CSharpInstance *create_for_managed_type(Object *p_owner, CSharpScript *p_script, const MonoGCHandleData &p_gchandle);
  268. public:
  269. _FORCE_INLINE_ bool is_destructing_script_instance() { return destructing_script_instance; }
  270. _FORCE_INLINE_ GCHandleIntPtr get_gchandle_intptr() { return gchandle.get_intptr(); }
  271. Object *get_owner() override;
  272. bool set(const StringName &p_name, const Variant &p_value) override;
  273. bool get(const StringName &p_name, Variant &r_ret) const override;
  274. void get_property_list(List<PropertyInfo> *p_properties) const override;
  275. Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const override;
  276. virtual void validate_property(PropertyInfo &p_property) const override;
  277. bool property_can_revert(const StringName &p_name) const override;
  278. bool property_get_revert(const StringName &p_name, Variant &r_ret) const override;
  279. void get_method_list(List<MethodInfo> *p_list) const override;
  280. bool has_method(const StringName &p_method) const override;
  281. virtual int get_method_argument_count(const StringName &p_method, bool *r_is_valid = nullptr) const override;
  282. Variant callp(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) override;
  283. void mono_object_disposed(GCHandleIntPtr p_gchandle_to_free);
  284. /*
  285. * If 'r_delete_owner' is set to true, the caller must memdelete the script instance's owner. Otherwise, if
  286. * 'r_remove_script_instance' is set to true, the caller must destroy the script instance by removing it from its owner.
  287. */
  288. void mono_object_disposed_baseref(GCHandleIntPtr p_gchandle_to_free, bool p_is_finalizer, bool &r_delete_owner, bool &r_remove_script_instance);
  289. void connect_event_signals();
  290. void disconnect_event_signals();
  291. void refcount_incremented() override;
  292. bool refcount_decremented() override;
  293. const Variant get_rpc_config() const override;
  294. void notification(int p_notification, bool p_reversed = false) override;
  295. void _call_notification(int p_notification, bool p_reversed = false);
  296. String to_string(bool *r_valid) override;
  297. Ref<Script> get_script() const override;
  298. ScriptLanguage *get_language() override;
  299. CSharpInstance(const Ref<CSharpScript> &p_script);
  300. ~CSharpInstance();
  301. };
  302. struct CSharpScriptBinding {
  303. bool inited = false;
  304. StringName type_name;
  305. MonoGCHandleData gchandle;
  306. Object *owner = nullptr;
  307. CSharpScriptBinding() {}
  308. };
  309. class ManagedCallableMiddleman : public Object {
  310. GDCLASS(ManagedCallableMiddleman, Object);
  311. };
  312. class CSharpLanguage : public ScriptLanguage {
  313. friend class CSharpScript;
  314. friend class CSharpInstance;
  315. static CSharpLanguage *singleton;
  316. bool finalizing = false;
  317. bool finalized = false;
  318. GDMono *gdmono = nullptr;
  319. SelfList<CSharpScript>::List script_list;
  320. Mutex script_instances_mutex;
  321. Mutex script_gchandle_release_mutex;
  322. Mutex language_bind_mutex;
  323. RBMap<Object *, CSharpScriptBinding> script_bindings;
  324. #ifdef DEBUG_ENABLED
  325. // List of unsafe object references
  326. HashMap<ObjectID, int> unsafe_object_references;
  327. Mutex unsafe_object_references_lock;
  328. #endif
  329. ManagedCallableMiddleman *managed_callable_middleman = memnew(ManagedCallableMiddleman);
  330. int lang_idx = -1;
  331. // For debug_break and debug_break_parse
  332. int _debug_parse_err_line = -1;
  333. String _debug_parse_err_file;
  334. String _debug_error;
  335. friend class GDMono;
  336. #ifdef TOOLS_ENABLED
  337. EditorPlugin *godotsharp_editor = nullptr;
  338. static void _editor_init_callback();
  339. #endif
  340. static void *_instance_binding_create_callback(void *p_token, void *p_instance);
  341. static void _instance_binding_free_callback(void *p_token, void *p_instance, void *p_binding);
  342. static GDExtensionBool _instance_binding_reference_callback(void *p_token, void *p_binding, GDExtensionBool p_reference);
  343. static GDExtensionInstanceBindingCallbacks _instance_binding_callbacks;
  344. public:
  345. static void *get_instance_binding(Object *p_object);
  346. static void *get_existing_instance_binding(Object *p_object);
  347. static void *get_instance_binding_with_setup(Object *p_object);
  348. static bool has_instance_binding(Object *p_object);
  349. const Mutex &get_language_bind_mutex() {
  350. return language_bind_mutex;
  351. }
  352. const Mutex &get_script_instances_mutex() {
  353. return script_instances_mutex;
  354. }
  355. _FORCE_INLINE_ int get_language_index() {
  356. return lang_idx;
  357. }
  358. void set_language_index(int p_idx);
  359. _FORCE_INLINE_ static CSharpLanguage *get_singleton() {
  360. return singleton;
  361. }
  362. #ifdef TOOLS_ENABLED
  363. _FORCE_INLINE_ EditorPlugin *get_godotsharp_editor() const {
  364. return godotsharp_editor;
  365. }
  366. #endif
  367. static void release_script_gchandle(MonoGCHandleData &p_gchandle);
  368. static void release_script_gchandle_thread_safe(GCHandleIntPtr p_gchandle_to_free, MonoGCHandleData &r_gchandle);
  369. static void release_binding_gchandle_thread_safe(GCHandleIntPtr p_gchandle_to_free, CSharpScriptBinding &r_script_binding);
  370. bool debug_break(const String &p_error, bool p_allow_continue = true);
  371. bool debug_break_parse(const String &p_file, int p_line, const String &p_error);
  372. #ifdef GD_MONO_HOT_RELOAD
  373. bool is_assembly_reloading_needed();
  374. void reload_assemblies(bool p_soft_reload);
  375. #endif
  376. _FORCE_INLINE_ ManagedCallableMiddleman *get_managed_callable_middleman() const {
  377. return managed_callable_middleman;
  378. }
  379. String get_name() const override;
  380. /* LANGUAGE FUNCTIONS */
  381. String get_type() const override;
  382. String get_extension() const override;
  383. void init() override;
  384. void finish() override;
  385. void finalize();
  386. /* EDITOR FUNCTIONS */
  387. void get_reserved_words(List<String> *p_words) const override;
  388. bool is_control_flow_keyword(const String &p_keyword) const override;
  389. void get_comment_delimiters(List<String> *p_delimiters) const override;
  390. void get_doc_comment_delimiters(List<String> *p_delimiters) const override;
  391. void get_string_delimiters(List<String> *p_delimiters) const override;
  392. bool is_using_templates() override;
  393. virtual Ref<Script> make_template(const String &p_template, const String &p_class_name, const String &p_base_class_name) const override;
  394. virtual Vector<ScriptTemplate> get_built_in_templates(const StringName &p_object) override;
  395. /* TODO */ bool validate(const String &p_script, const String &p_path, List<String> *r_functions,
  396. List<ScriptLanguage::ScriptError> *r_errors = nullptr, List<ScriptLanguage::Warning> *r_warnings = nullptr, HashSet<int> *r_safe_lines = nullptr) const override {
  397. return true;
  398. }
  399. String validate_path(const String &p_path) const override;
  400. Script *create_script() const override;
  401. #ifndef DISABLE_DEPRECATED
  402. virtual bool has_named_classes() const override { return false; }
  403. #endif
  404. bool supports_builtin_mode() const override;
  405. /* TODO? */ int find_function(const String &p_function, const String &p_code) const override {
  406. return -1;
  407. }
  408. String make_function(const String &p_class, const String &p_name, const PackedStringArray &p_args) const override;
  409. virtual bool can_make_function() const override { return false; }
  410. virtual String _get_indentation() const;
  411. /* TODO? */ void auto_indent_code(String &p_code, int p_from_line, int p_to_line) const override {}
  412. /* TODO */ void add_global_constant(const StringName &p_variable, const Variant &p_value) override {}
  413. virtual ScriptNameCasing preferred_file_name_casing() const override;
  414. /* SCRIPT GLOBAL CLASS FUNCTIONS */
  415. virtual bool handles_global_class_type(const String &p_type) const override;
  416. virtual String get_global_class_name(const String &p_path, String *r_base_type = nullptr, String *r_icon_path = nullptr) const override;
  417. /* DEBUGGER FUNCTIONS */
  418. String debug_get_error() const override;
  419. int debug_get_stack_level_count() const override;
  420. int debug_get_stack_level_line(int p_level) const override;
  421. String debug_get_stack_level_function(int p_level) const override;
  422. String debug_get_stack_level_source(int p_level) const override;
  423. /* TODO */ void debug_get_stack_level_locals(int p_level, List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) override {}
  424. /* TODO */ void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) override {}
  425. /* TODO */ void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) override {}
  426. /* TODO */ String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) override {
  427. return "";
  428. }
  429. Vector<StackInfo> debug_get_current_stack_info() override;
  430. /* PROFILING FUNCTIONS */
  431. /* TODO */ void profiling_start() override {}
  432. /* TODO */ void profiling_stop() override {}
  433. /* TODO */ void profiling_set_save_native_calls(bool p_enable) override {}
  434. /* TODO */ int profiling_get_accumulated_data(ProfilingInfo *p_info_arr, int p_info_max) override {
  435. return 0;
  436. }
  437. /* TODO */ int profiling_get_frame_data(ProfilingInfo *p_info_arr, int p_info_max) override {
  438. return 0;
  439. }
  440. void frame() override;
  441. /* TODO? */ void get_public_functions(List<MethodInfo> *p_functions) const override {}
  442. /* TODO? */ void get_public_constants(List<Pair<String, Variant>> *p_constants) const override {}
  443. /* TODO? */ void get_public_annotations(List<MethodInfo> *p_annotations) const override {}
  444. void reload_all_scripts() override;
  445. void reload_scripts(const Array &p_scripts, bool p_soft_reload) override;
  446. void reload_tool_script(const Ref<Script> &p_script, bool p_soft_reload) override;
  447. /* LOADER FUNCTIONS */
  448. void get_recognized_extensions(List<String> *p_extensions) const override;
  449. #ifdef TOOLS_ENABLED
  450. Error open_in_external_editor(const Ref<Script> &p_script, int p_line, int p_col) override;
  451. bool overrides_external_editor() override;
  452. #endif
  453. RBMap<Object *, CSharpScriptBinding>::Element *insert_script_binding(Object *p_object, const CSharpScriptBinding &p_script_binding);
  454. bool setup_csharp_script_binding(CSharpScriptBinding &r_script_binding, Object *p_object);
  455. static void tie_native_managed_to_unmanaged(GCHandleIntPtr p_gchandle_intptr, Object *p_unmanaged, const StringName *p_native_name, bool p_ref_counted);
  456. static void tie_user_managed_to_unmanaged(GCHandleIntPtr p_gchandle_intptr, Object *p_unmanaged, Ref<CSharpScript> *p_script, bool p_ref_counted);
  457. static void tie_managed_to_unmanaged_with_pre_setup(GCHandleIntPtr p_gchandle_intptr, Object *p_unmanaged);
  458. void post_unsafe_reference(Object *p_obj);
  459. void pre_unsafe_unreference(Object *p_obj);
  460. CSharpLanguage();
  461. ~CSharpLanguage();
  462. };
  463. class ResourceFormatLoaderCSharpScript : public ResourceFormatLoader {
  464. public:
  465. Ref<Resource> load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, CacheMode p_cache_mode = CACHE_MODE_REUSE) override;
  466. void get_recognized_extensions(List<String> *p_extensions) const override;
  467. bool handles_type(const String &p_type) const override;
  468. String get_resource_type(const String &p_path) const override;
  469. };
  470. class ResourceFormatSaverCSharpScript : public ResourceFormatSaver {
  471. public:
  472. Error save(const Ref<Resource> &p_resource, const String &p_path, uint32_t p_flags = 0) override;
  473. void get_recognized_extensions(const Ref<Resource> &p_resource, List<String> *p_extensions) const override;
  474. bool recognize(const Ref<Resource> &p_resource) const override;
  475. };
  476. #endif // CSHARP_SCRIPT_H