csharp_script.h 22 KB

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