runtime_interop.cpp 56 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  1. /**************************************************************************/
  2. /* runtime_interop.cpp */
  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. #include "runtime_interop.h"
  31. #include "../csharp_script.h"
  32. #include "../interop_types.h"
  33. #include "../managed_callable.h"
  34. #include "../mono_gd/gd_mono_cache.h"
  35. #include "../signal_awaiter_utils.h"
  36. #include "../utils/path_utils.h"
  37. #include "core/config/engine.h"
  38. #include "core/config/project_settings.h"
  39. #include "core/debugger/engine_debugger.h"
  40. #include "core/debugger/script_debugger.h"
  41. #include "core/io/marshalls.h"
  42. #include "core/object/class_db.h"
  43. #include "core/object/method_bind.h"
  44. #include "core/os/os.h"
  45. #include "core/string/string_name.h"
  46. #ifdef TOOLS_ENABLED
  47. #include "editor/editor_file_system.h"
  48. #endif
  49. #ifdef __cplusplus
  50. extern "C" {
  51. #endif
  52. // For ArrayPrivate and DictionaryPrivate
  53. static_assert(sizeof(SafeRefCount) == sizeof(uint32_t));
  54. typedef Object *(*godotsharp_class_creation_func)();
  55. bool godotsharp_dotnet_module_is_initialized() {
  56. return GDMono::get_singleton()->is_initialized();
  57. }
  58. MethodBind *godotsharp_method_bind_get_method(const StringName *p_classname, const StringName *p_methodname) {
  59. return ClassDB::get_method(*p_classname, *p_methodname);
  60. }
  61. MethodBind *godotsharp_method_bind_get_method_with_compatibility(const StringName *p_classname, const StringName *p_methodname, uint64_t p_hash) {
  62. return ClassDB::get_method_with_compatibility(*p_classname, *p_methodname, p_hash);
  63. }
  64. godotsharp_class_creation_func godotsharp_get_class_constructor(const StringName *p_classname) {
  65. ClassDB::ClassInfo *class_info = ClassDB::classes.getptr(*p_classname);
  66. if (class_info) {
  67. return class_info->creation_func;
  68. }
  69. return nullptr;
  70. }
  71. Object *godotsharp_engine_get_singleton(const String *p_name) {
  72. return Engine::get_singleton()->get_singleton_object(*p_name);
  73. }
  74. int32_t godotsharp_stack_info_vector_resize(
  75. Vector<ScriptLanguage::StackInfo> *p_stack_info_vector, int p_size) {
  76. return (int32_t)p_stack_info_vector->resize(p_size);
  77. }
  78. void godotsharp_stack_info_vector_destroy(
  79. Vector<ScriptLanguage::StackInfo> *p_stack_info_vector) {
  80. p_stack_info_vector->~Vector();
  81. }
  82. void godotsharp_internal_script_debugger_send_error(const String *p_func,
  83. const String *p_file, int32_t p_line, const String *p_err, const String *p_descr,
  84. ErrorHandlerType p_type, const Vector<ScriptLanguage::StackInfo> *p_stack_info_vector) {
  85. const String file = ProjectSettings::get_singleton()->localize_path(p_file->simplify_path());
  86. EngineDebugger::get_script_debugger()->send_error(*p_func, file, p_line, *p_err, *p_descr,
  87. true, p_type, *p_stack_info_vector);
  88. }
  89. bool godotsharp_internal_script_debugger_is_active() {
  90. return EngineDebugger::is_active();
  91. }
  92. GCHandleIntPtr godotsharp_internal_object_get_associated_gchandle(Object *p_ptr) {
  93. #ifdef DEBUG_ENABLED
  94. CRASH_COND(p_ptr == nullptr);
  95. #endif
  96. if (p_ptr->get_script_instance()) {
  97. CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(p_ptr->get_script_instance());
  98. if (cs_instance) {
  99. if (!cs_instance->is_destructing_script_instance()) {
  100. return cs_instance->get_gchandle_intptr();
  101. }
  102. return { nullptr };
  103. }
  104. }
  105. void *data = CSharpLanguage::get_existing_instance_binding(p_ptr);
  106. if (data) {
  107. CSharpScriptBinding &script_binding = ((RBMap<Object *, CSharpScriptBinding>::Element *)data)->get();
  108. if (script_binding.inited) {
  109. MonoGCHandleData &gchandle = script_binding.gchandle;
  110. return !gchandle.is_released() ? gchandle.get_intptr() : GCHandleIntPtr{ nullptr };
  111. }
  112. }
  113. return { nullptr };
  114. }
  115. void godotsharp_internal_object_disposed(Object *p_ptr, GCHandleIntPtr p_gchandle_to_free) {
  116. #ifdef DEBUG_ENABLED
  117. CRASH_COND(p_ptr == nullptr);
  118. #endif
  119. if (p_ptr->get_script_instance()) {
  120. CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(p_ptr->get_script_instance());
  121. if (cs_instance) {
  122. if (!cs_instance->is_destructing_script_instance()) {
  123. cs_instance->mono_object_disposed(p_gchandle_to_free);
  124. p_ptr->set_script_instance(nullptr);
  125. }
  126. return;
  127. }
  128. }
  129. void *data = CSharpLanguage::get_existing_instance_binding(p_ptr);
  130. if (data) {
  131. CSharpScriptBinding &script_binding = ((RBMap<Object *, CSharpScriptBinding>::Element *)data)->get();
  132. if (script_binding.inited) {
  133. if (!script_binding.gchandle.is_released()) {
  134. CSharpLanguage::release_binding_gchandle_thread_safe(p_gchandle_to_free, script_binding);
  135. }
  136. }
  137. }
  138. }
  139. void godotsharp_internal_refcounted_disposed(Object *p_ptr, GCHandleIntPtr p_gchandle_to_free, bool p_is_finalizer) {
  140. #ifdef DEBUG_ENABLED
  141. CRASH_COND(p_ptr == nullptr);
  142. // This is only called with RefCounted derived classes
  143. CRASH_COND(!Object::cast_to<RefCounted>(p_ptr));
  144. #endif
  145. RefCounted *rc = static_cast<RefCounted *>(p_ptr);
  146. if (rc->get_script_instance()) {
  147. CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(rc->get_script_instance());
  148. if (cs_instance) {
  149. if (!cs_instance->is_destructing_script_instance()) {
  150. bool delete_owner;
  151. bool remove_script_instance;
  152. cs_instance->mono_object_disposed_baseref(p_gchandle_to_free, p_is_finalizer,
  153. delete_owner, remove_script_instance);
  154. if (delete_owner) {
  155. memdelete(rc);
  156. } else if (remove_script_instance) {
  157. rc->set_script_instance(nullptr);
  158. }
  159. }
  160. return;
  161. }
  162. }
  163. // Unsafe refcount decrement. The managed instance also counts as a reference.
  164. // See: CSharpLanguage::alloc_instance_binding_data(Object *p_object)
  165. CSharpLanguage::get_singleton()->pre_unsafe_unreference(rc);
  166. if (rc->unreference()) {
  167. memdelete(rc);
  168. } else {
  169. void *data = CSharpLanguage::get_existing_instance_binding(rc);
  170. if (data) {
  171. CSharpScriptBinding &script_binding = ((RBMap<Object *, CSharpScriptBinding>::Element *)data)->get();
  172. if (script_binding.inited) {
  173. if (!script_binding.gchandle.is_released()) {
  174. CSharpLanguage::release_binding_gchandle_thread_safe(p_gchandle_to_free, script_binding);
  175. }
  176. }
  177. }
  178. }
  179. }
  180. int32_t godotsharp_internal_signal_awaiter_connect(Object *p_source, StringName *p_signal, Object *p_target, GCHandleIntPtr p_awaiter_handle_ptr) {
  181. StringName signal = p_signal ? *p_signal : StringName();
  182. return (int32_t)gd_mono_connect_signal_awaiter(p_source, signal, p_target, p_awaiter_handle_ptr);
  183. }
  184. GCHandleIntPtr godotsharp_internal_unmanaged_get_script_instance_managed(Object *p_unmanaged, bool *r_has_cs_script_instance) {
  185. #ifdef DEBUG_ENABLED
  186. CRASH_COND(!p_unmanaged);
  187. CRASH_COND(!r_has_cs_script_instance);
  188. #endif
  189. if (p_unmanaged->get_script_instance()) {
  190. CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(p_unmanaged->get_script_instance());
  191. if (cs_instance) {
  192. *r_has_cs_script_instance = true;
  193. return cs_instance->get_gchandle_intptr();
  194. }
  195. }
  196. *r_has_cs_script_instance = false;
  197. return { nullptr };
  198. }
  199. GCHandleIntPtr godotsharp_internal_unmanaged_get_instance_binding_managed(Object *p_unmanaged) {
  200. #ifdef DEBUG_ENABLED
  201. CRASH_COND(!p_unmanaged);
  202. #endif
  203. void *data = CSharpLanguage::get_instance_binding_with_setup(p_unmanaged);
  204. ERR_FAIL_NULL_V(data, { nullptr });
  205. CSharpScriptBinding &script_binding = ((RBMap<Object *, CSharpScriptBinding>::Element *)data)->value();
  206. ERR_FAIL_COND_V(!script_binding.inited, { nullptr });
  207. return script_binding.gchandle.get_intptr();
  208. }
  209. GCHandleIntPtr godotsharp_internal_unmanaged_instance_binding_create_managed(Object *p_unmanaged, GCHandleIntPtr p_old_gchandle) {
  210. #ifdef DEBUG_ENABLED
  211. CRASH_COND(!p_unmanaged);
  212. #endif
  213. void *data = CSharpLanguage::get_instance_binding_with_setup(p_unmanaged);
  214. ERR_FAIL_NULL_V(data, { nullptr });
  215. CSharpScriptBinding &script_binding = ((RBMap<Object *, CSharpScriptBinding>::Element *)data)->value();
  216. ERR_FAIL_COND_V(!script_binding.inited, { nullptr });
  217. MonoGCHandleData &gchandle = script_binding.gchandle;
  218. // TODO: Possible data race?
  219. CRASH_COND(gchandle.get_intptr().value != p_old_gchandle.value);
  220. CSharpLanguage::get_singleton()->release_script_gchandle(gchandle);
  221. script_binding.inited = false;
  222. // Create a new one
  223. #ifdef DEBUG_ENABLED
  224. CRASH_COND(script_binding.type_name == StringName());
  225. #endif
  226. bool parent_is_object_class = ClassDB::is_parent_class(p_unmanaged->get_class_name(), script_binding.type_name);
  227. ERR_FAIL_COND_V_MSG(!parent_is_object_class, { nullptr },
  228. "Type inherits from native type '" + script_binding.type_name + "', so it can't be instantiated in object of type: '" + p_unmanaged->get_class() + "'.");
  229. GCHandleIntPtr strong_gchandle =
  230. GDMonoCache::managed_callbacks.ScriptManagerBridge_CreateManagedForGodotObjectBinding(
  231. &script_binding.type_name, p_unmanaged);
  232. ERR_FAIL_NULL_V(strong_gchandle.value, { nullptr });
  233. gchandle = MonoGCHandleData(strong_gchandle, gdmono::GCHandleType::STRONG_HANDLE);
  234. script_binding.inited = true;
  235. // Tie managed to unmanaged
  236. RefCounted *rc = Object::cast_to<RefCounted>(p_unmanaged);
  237. if (rc) {
  238. // Unsafe refcount increment. The managed instance also counts as a reference.
  239. // This way if the unmanaged world has no references to our owner
  240. // but the managed instance is alive, the refcount will be 1 instead of 0.
  241. // See: godot_icall_RefCounted_Dtor(MonoObject *p_obj, Object *p_ptr)
  242. rc->reference();
  243. CSharpLanguage::get_singleton()->post_unsafe_reference(rc);
  244. }
  245. return gchandle.get_intptr();
  246. }
  247. void godotsharp_internal_tie_native_managed_to_unmanaged(GCHandleIntPtr p_gchandle_intptr, Object *p_unmanaged, const StringName *p_native_name, bool p_ref_counted) {
  248. CSharpLanguage::tie_native_managed_to_unmanaged(p_gchandle_intptr, p_unmanaged, p_native_name, p_ref_counted);
  249. }
  250. void godotsharp_internal_tie_user_managed_to_unmanaged(GCHandleIntPtr p_gchandle_intptr, Object *p_unmanaged, Ref<CSharpScript> *p_script, bool p_ref_counted) {
  251. CSharpLanguage::tie_user_managed_to_unmanaged(p_gchandle_intptr, p_unmanaged, p_script, p_ref_counted);
  252. }
  253. void godotsharp_internal_tie_managed_to_unmanaged_with_pre_setup(GCHandleIntPtr p_gchandle_intptr, Object *p_unmanaged) {
  254. CSharpLanguage::tie_managed_to_unmanaged_with_pre_setup(p_gchandle_intptr, p_unmanaged);
  255. }
  256. void godotsharp_internal_new_csharp_script(Ref<CSharpScript> *r_dest) {
  257. memnew_placement(r_dest, Ref<CSharpScript>(memnew(CSharpScript)));
  258. }
  259. void godotsharp_internal_editor_file_system_update_file(const String *p_script_path) {
  260. #ifdef TOOLS_ENABLED
  261. // If the EditorFileSystem singleton is available, update the file;
  262. // otherwise, the file will be updated when the singleton becomes available.
  263. EditorFileSystem *efs = EditorFileSystem::get_singleton();
  264. if (efs) {
  265. efs->update_file(*p_script_path);
  266. }
  267. #else
  268. // EditorFileSystem is only available when running in the Godot editor.
  269. DEV_ASSERT(false);
  270. #endif
  271. }
  272. bool godotsharp_internal_script_load(const String *p_path, Ref<CSharpScript> *r_dest) {
  273. Ref<Resource> res = ResourceLoader::load(*p_path);
  274. if (res.is_valid()) {
  275. memnew_placement(r_dest, Ref<CSharpScript>(res));
  276. return true;
  277. } else {
  278. memnew_placement(r_dest, Ref<CSharpScript>());
  279. return false;
  280. }
  281. }
  282. void godotsharp_internal_reload_registered_script(CSharpScript *p_script) {
  283. CRASH_COND(!p_script);
  284. CSharpScript::reload_registered_script(Ref<CSharpScript>(p_script));
  285. }
  286. void godotsharp_array_filter_godot_objects_by_native(StringName *p_native_name, const Array *p_input, Array *r_output) {
  287. memnew_placement(r_output, Array);
  288. for (int i = 0; i < p_input->size(); ++i) {
  289. if (ClassDB::is_parent_class(((Object *)(*p_input)[i])->get_class(), *p_native_name)) {
  290. r_output->push_back(p_input[i]);
  291. }
  292. }
  293. }
  294. void godotsharp_array_filter_godot_objects_by_non_native(const Array *p_input, Array *r_output) {
  295. memnew_placement(r_output, Array);
  296. for (int i = 0; i < p_input->size(); ++i) {
  297. CSharpInstance *si = CAST_CSHARP_INSTANCE(((Object *)(*p_input)[i])->get_script_instance());
  298. if (si != nullptr) {
  299. r_output->push_back(p_input[i]);
  300. }
  301. }
  302. }
  303. void godotsharp_ref_new_from_ref_counted_ptr(Ref<RefCounted> *r_dest, RefCounted *p_ref_counted_ptr) {
  304. memnew_placement(r_dest, Ref<RefCounted>(p_ref_counted_ptr));
  305. }
  306. void godotsharp_ref_destroy(Ref<RefCounted> *p_instance) {
  307. p_instance->~Ref();
  308. }
  309. void godotsharp_string_name_new_from_string(StringName *r_dest, const String *p_name) {
  310. memnew_placement(r_dest, StringName(*p_name));
  311. }
  312. void godotsharp_node_path_new_from_string(NodePath *r_dest, const String *p_name) {
  313. memnew_placement(r_dest, NodePath(*p_name));
  314. }
  315. void godotsharp_string_name_as_string(String *r_dest, const StringName *p_name) {
  316. memnew_placement(r_dest, String(p_name->operator String()));
  317. }
  318. void godotsharp_node_path_as_string(String *r_dest, const NodePath *p_np) {
  319. memnew_placement(r_dest, String(p_np->operator String()));
  320. }
  321. godot_packed_array godotsharp_packed_byte_array_new_mem_copy(const uint8_t *p_src, int32_t p_length) {
  322. godot_packed_array ret;
  323. memnew_placement(&ret, PackedByteArray);
  324. PackedByteArray *array = reinterpret_cast<PackedByteArray *>(&ret);
  325. array->resize(p_length);
  326. uint8_t *dst = array->ptrw();
  327. memcpy(dst, p_src, p_length * sizeof(uint8_t));
  328. return ret;
  329. }
  330. godot_packed_array godotsharp_packed_int32_array_new_mem_copy(const int32_t *p_src, int32_t p_length) {
  331. godot_packed_array ret;
  332. memnew_placement(&ret, PackedInt32Array);
  333. PackedInt32Array *array = reinterpret_cast<PackedInt32Array *>(&ret);
  334. array->resize(p_length);
  335. int32_t *dst = array->ptrw();
  336. memcpy(dst, p_src, p_length * sizeof(int32_t));
  337. return ret;
  338. }
  339. godot_packed_array godotsharp_packed_int64_array_new_mem_copy(const int64_t *p_src, int32_t p_length) {
  340. godot_packed_array ret;
  341. memnew_placement(&ret, PackedInt64Array);
  342. PackedInt64Array *array = reinterpret_cast<PackedInt64Array *>(&ret);
  343. array->resize(p_length);
  344. int64_t *dst = array->ptrw();
  345. memcpy(dst, p_src, p_length * sizeof(int64_t));
  346. return ret;
  347. }
  348. godot_packed_array godotsharp_packed_float32_array_new_mem_copy(const float *p_src, int32_t p_length) {
  349. godot_packed_array ret;
  350. memnew_placement(&ret, PackedFloat32Array);
  351. PackedFloat32Array *array = reinterpret_cast<PackedFloat32Array *>(&ret);
  352. array->resize(p_length);
  353. float *dst = array->ptrw();
  354. memcpy(dst, p_src, p_length * sizeof(float));
  355. return ret;
  356. }
  357. godot_packed_array godotsharp_packed_float64_array_new_mem_copy(const double *p_src, int32_t p_length) {
  358. godot_packed_array ret;
  359. memnew_placement(&ret, PackedFloat64Array);
  360. PackedFloat64Array *array = reinterpret_cast<PackedFloat64Array *>(&ret);
  361. array->resize(p_length);
  362. double *dst = array->ptrw();
  363. memcpy(dst, p_src, p_length * sizeof(double));
  364. return ret;
  365. }
  366. godot_packed_array godotsharp_packed_vector2_array_new_mem_copy(const Vector2 *p_src, int32_t p_length) {
  367. godot_packed_array ret;
  368. memnew_placement(&ret, PackedVector2Array);
  369. PackedVector2Array *array = reinterpret_cast<PackedVector2Array *>(&ret);
  370. array->resize(p_length);
  371. Vector2 *dst = array->ptrw();
  372. memcpy(dst, p_src, p_length * sizeof(Vector2));
  373. return ret;
  374. }
  375. godot_packed_array godotsharp_packed_vector3_array_new_mem_copy(const Vector3 *p_src, int32_t p_length) {
  376. godot_packed_array ret;
  377. memnew_placement(&ret, PackedVector3Array);
  378. PackedVector3Array *array = reinterpret_cast<PackedVector3Array *>(&ret);
  379. array->resize(p_length);
  380. Vector3 *dst = array->ptrw();
  381. memcpy(dst, p_src, p_length * sizeof(Vector3));
  382. return ret;
  383. }
  384. godot_packed_array godotsharp_packed_vector4_array_new_mem_copy(const Vector4 *p_src, int32_t p_length) {
  385. godot_packed_array ret;
  386. memnew_placement(&ret, PackedVector4Array);
  387. PackedVector4Array *array = reinterpret_cast<PackedVector4Array *>(&ret);
  388. array->resize(p_length);
  389. Vector4 *dst = array->ptrw();
  390. memcpy(dst, p_src, p_length * sizeof(Vector4));
  391. return ret;
  392. }
  393. godot_packed_array godotsharp_packed_color_array_new_mem_copy(const Color *p_src, int32_t p_length) {
  394. godot_packed_array ret;
  395. memnew_placement(&ret, PackedColorArray);
  396. PackedColorArray *array = reinterpret_cast<PackedColorArray *>(&ret);
  397. array->resize(p_length);
  398. Color *dst = array->ptrw();
  399. memcpy(dst, p_src, p_length * sizeof(Color));
  400. return ret;
  401. }
  402. void godotsharp_packed_string_array_add(PackedStringArray *r_dest, const String *p_element) {
  403. r_dest->append(*p_element);
  404. }
  405. void godotsharp_callable_new_with_delegate(GCHandleIntPtr p_delegate_handle, void *p_trampoline,
  406. const Object *p_object, Callable *r_callable) {
  407. // TODO: Use pooling for ManagedCallable instances.
  408. ObjectID objid = p_object ? p_object->get_instance_id() : ObjectID();
  409. CallableCustom *managed_callable = memnew(ManagedCallable(p_delegate_handle, p_trampoline, objid));
  410. memnew_placement(r_callable, Callable(managed_callable));
  411. }
  412. bool godotsharp_callable_get_data_for_marshalling(const Callable *p_callable,
  413. GCHandleIntPtr *r_delegate_handle, void **r_trampoline, Object **r_object, StringName *r_name) {
  414. if (p_callable->is_custom()) {
  415. CallableCustom *custom = p_callable->get_custom();
  416. CallableCustom::CompareEqualFunc compare_equal_func = custom->get_compare_equal_func();
  417. if (compare_equal_func == ManagedCallable::compare_equal_func_ptr) {
  418. ManagedCallable *managed_callable = static_cast<ManagedCallable *>(custom);
  419. *r_delegate_handle = managed_callable->get_delegate();
  420. *r_trampoline = managed_callable->get_trampoline();
  421. *r_object = nullptr;
  422. memnew_placement(r_name, StringName());
  423. return true;
  424. } else if (compare_equal_func == SignalAwaiterCallable::compare_equal_func_ptr) {
  425. SignalAwaiterCallable *signal_awaiter_callable = static_cast<SignalAwaiterCallable *>(custom);
  426. *r_delegate_handle = { nullptr };
  427. *r_trampoline = nullptr;
  428. *r_object = ObjectDB::get_instance(signal_awaiter_callable->get_object());
  429. memnew_placement(r_name, StringName(signal_awaiter_callable->get_signal()));
  430. return true;
  431. } else if (compare_equal_func == EventSignalCallable::compare_equal_func_ptr) {
  432. EventSignalCallable *event_signal_callable = static_cast<EventSignalCallable *>(custom);
  433. *r_delegate_handle = { nullptr };
  434. *r_trampoline = nullptr;
  435. *r_object = ObjectDB::get_instance(event_signal_callable->get_object());
  436. memnew_placement(r_name, StringName(event_signal_callable->get_signal()));
  437. return true;
  438. }
  439. // Some other CallableCustom. We only support ManagedCallable.
  440. *r_delegate_handle = { nullptr };
  441. *r_trampoline = nullptr;
  442. *r_object = nullptr;
  443. memnew_placement(r_name, StringName());
  444. return false;
  445. } else {
  446. *r_delegate_handle = { nullptr };
  447. *r_trampoline = nullptr;
  448. *r_object = ObjectDB::get_instance(p_callable->get_object_id());
  449. memnew_placement(r_name, StringName(p_callable->get_method()));
  450. return true;
  451. }
  452. }
  453. godot_variant godotsharp_callable_call(Callable *p_callable, const Variant **p_args, const int32_t p_arg_count, Callable::CallError *p_call_error) {
  454. godot_variant ret;
  455. memnew_placement(&ret, Variant);
  456. Variant *ret_val = (Variant *)&ret;
  457. p_callable->callp(p_args, p_arg_count, *ret_val, *p_call_error);
  458. return ret;
  459. }
  460. void godotsharp_callable_call_deferred(Callable *p_callable, const Variant **p_args, const int32_t p_arg_count) {
  461. p_callable->call_deferredp(p_args, p_arg_count);
  462. }
  463. godot_color godotsharp_color_from_ok_hsl(float p_h, float p_s, float p_l, float p_alpha) {
  464. godot_color ret;
  465. Color *dest = (Color *)&ret;
  466. memnew_placement(dest, Color(Color::from_ok_hsl(p_h, p_s, p_l, p_alpha)));
  467. return ret;
  468. }
  469. // GDNative functions
  470. // gdnative.h
  471. void godotsharp_method_bind_ptrcall(MethodBind *p_method_bind, Object *p_instance, const void **p_args, void *p_ret) {
  472. p_method_bind->ptrcall(p_instance, p_args, p_ret);
  473. }
  474. godot_variant godotsharp_method_bind_call(MethodBind *p_method_bind, Object *p_instance, const godot_variant **p_args, const int32_t p_arg_count, Callable::CallError *p_call_error) {
  475. godot_variant ret;
  476. memnew_placement(&ret, Variant());
  477. Variant *ret_val = (Variant *)&ret;
  478. *ret_val = p_method_bind->call(p_instance, (const Variant **)p_args, p_arg_count, *p_call_error);
  479. return ret;
  480. }
  481. // variant.h
  482. void godotsharp_variant_new_copy(godot_variant *r_dest, const Variant *p_src) {
  483. memnew_placement(r_dest, Variant(*p_src));
  484. }
  485. void godotsharp_variant_new_string_name(godot_variant *r_dest, const StringName *p_s) {
  486. memnew_placement(r_dest, Variant(*p_s));
  487. }
  488. void godotsharp_variant_new_node_path(godot_variant *r_dest, const NodePath *p_np) {
  489. memnew_placement(r_dest, Variant(*p_np));
  490. }
  491. void godotsharp_variant_new_object(godot_variant *r_dest, const Object *p_obj) {
  492. memnew_placement(r_dest, Variant(p_obj));
  493. }
  494. void godotsharp_variant_new_transform2d(godot_variant *r_dest, const Transform2D *p_t2d) {
  495. memnew_placement(r_dest, Variant(*p_t2d));
  496. }
  497. void godotsharp_variant_new_basis(godot_variant *r_dest, const Basis *p_basis) {
  498. memnew_placement(r_dest, Variant(*p_basis));
  499. }
  500. void godotsharp_variant_new_transform3d(godot_variant *r_dest, const Transform3D *p_trans) {
  501. memnew_placement(r_dest, Variant(*p_trans));
  502. }
  503. void godotsharp_variant_new_projection(godot_variant *r_dest, const Projection *p_proj) {
  504. memnew_placement(r_dest, Variant(*p_proj));
  505. }
  506. void godotsharp_variant_new_aabb(godot_variant *r_dest, const AABB *p_aabb) {
  507. memnew_placement(r_dest, Variant(*p_aabb));
  508. }
  509. void godotsharp_variant_new_dictionary(godot_variant *r_dest, const Dictionary *p_dict) {
  510. memnew_placement(r_dest, Variant(*p_dict));
  511. }
  512. void godotsharp_variant_new_array(godot_variant *r_dest, const Array *p_arr) {
  513. memnew_placement(r_dest, Variant(*p_arr));
  514. }
  515. void godotsharp_variant_new_packed_byte_array(godot_variant *r_dest, const PackedByteArray *p_pba) {
  516. memnew_placement(r_dest, Variant(*p_pba));
  517. }
  518. void godotsharp_variant_new_packed_int32_array(godot_variant *r_dest, const PackedInt32Array *p_pia) {
  519. memnew_placement(r_dest, Variant(*p_pia));
  520. }
  521. void godotsharp_variant_new_packed_int64_array(godot_variant *r_dest, const PackedInt64Array *p_pia) {
  522. memnew_placement(r_dest, Variant(*p_pia));
  523. }
  524. void godotsharp_variant_new_packed_float32_array(godot_variant *r_dest, const PackedFloat32Array *p_pra) {
  525. memnew_placement(r_dest, Variant(*p_pra));
  526. }
  527. void godotsharp_variant_new_packed_float64_array(godot_variant *r_dest, const PackedFloat64Array *p_pra) {
  528. memnew_placement(r_dest, Variant(*p_pra));
  529. }
  530. void godotsharp_variant_new_packed_string_array(godot_variant *r_dest, const PackedStringArray *p_psa) {
  531. memnew_placement(r_dest, Variant(*p_psa));
  532. }
  533. void godotsharp_variant_new_packed_vector2_array(godot_variant *r_dest, const PackedVector2Array *p_pv2a) {
  534. memnew_placement(r_dest, Variant(*p_pv2a));
  535. }
  536. void godotsharp_variant_new_packed_vector3_array(godot_variant *r_dest, const PackedVector3Array *p_pv3a) {
  537. memnew_placement(r_dest, Variant(*p_pv3a));
  538. }
  539. void godotsharp_variant_new_packed_vector4_array(godot_variant *r_dest, const PackedVector4Array *p_pv4a) {
  540. memnew_placement(r_dest, Variant(*p_pv4a));
  541. }
  542. void godotsharp_variant_new_packed_color_array(godot_variant *r_dest, const PackedColorArray *p_pca) {
  543. memnew_placement(r_dest, Variant(*p_pca));
  544. }
  545. bool godotsharp_variant_as_bool(const Variant *p_self) {
  546. return p_self->operator bool();
  547. }
  548. int64_t godotsharp_variant_as_int(const Variant *p_self) {
  549. return p_self->operator int64_t();
  550. }
  551. double godotsharp_variant_as_float(const Variant *p_self) {
  552. return p_self->operator double();
  553. }
  554. godot_string godotsharp_variant_as_string(const Variant *p_self) {
  555. godot_string raw_dest;
  556. String *dest = (String *)&raw_dest;
  557. memnew_placement(dest, String(p_self->operator String()));
  558. return raw_dest;
  559. }
  560. godot_vector2 godotsharp_variant_as_vector2(const Variant *p_self) {
  561. godot_vector2 raw_dest;
  562. Vector2 *dest = (Vector2 *)&raw_dest;
  563. memnew_placement(dest, Vector2(p_self->operator Vector2()));
  564. return raw_dest;
  565. }
  566. godot_vector2i godotsharp_variant_as_vector2i(const Variant *p_self) {
  567. godot_vector2i raw_dest;
  568. Vector2i *dest = (Vector2i *)&raw_dest;
  569. memnew_placement(dest, Vector2i(p_self->operator Vector2i()));
  570. return raw_dest;
  571. }
  572. godot_rect2 godotsharp_variant_as_rect2(const Variant *p_self) {
  573. godot_rect2 raw_dest;
  574. Rect2 *dest = (Rect2 *)&raw_dest;
  575. memnew_placement(dest, Rect2(p_self->operator Rect2()));
  576. return raw_dest;
  577. }
  578. godot_rect2i godotsharp_variant_as_rect2i(const Variant *p_self) {
  579. godot_rect2i raw_dest;
  580. Rect2i *dest = (Rect2i *)&raw_dest;
  581. memnew_placement(dest, Rect2i(p_self->operator Rect2i()));
  582. return raw_dest;
  583. }
  584. godot_vector3 godotsharp_variant_as_vector3(const Variant *p_self) {
  585. godot_vector3 raw_dest;
  586. Vector3 *dest = (Vector3 *)&raw_dest;
  587. memnew_placement(dest, Vector3(p_self->operator Vector3()));
  588. return raw_dest;
  589. }
  590. godot_vector3i godotsharp_variant_as_vector3i(const Variant *p_self) {
  591. godot_vector3i raw_dest;
  592. Vector3i *dest = (Vector3i *)&raw_dest;
  593. memnew_placement(dest, Vector3i(p_self->operator Vector3i()));
  594. return raw_dest;
  595. }
  596. godot_transform2d godotsharp_variant_as_transform2d(const Variant *p_self) {
  597. godot_transform2d raw_dest;
  598. Transform2D *dest = (Transform2D *)&raw_dest;
  599. memnew_placement(dest, Transform2D(p_self->operator Transform2D()));
  600. return raw_dest;
  601. }
  602. godot_vector4 godotsharp_variant_as_vector4(const Variant *p_self) {
  603. godot_vector4 raw_dest;
  604. Vector4 *dest = (Vector4 *)&raw_dest;
  605. memnew_placement(dest, Vector4(p_self->operator Vector4()));
  606. return raw_dest;
  607. }
  608. godot_vector4i godotsharp_variant_as_vector4i(const Variant *p_self) {
  609. godot_vector4i raw_dest;
  610. Vector4i *dest = (Vector4i *)&raw_dest;
  611. memnew_placement(dest, Vector4i(p_self->operator Vector4i()));
  612. return raw_dest;
  613. }
  614. godot_plane godotsharp_variant_as_plane(const Variant *p_self) {
  615. godot_plane raw_dest;
  616. Plane *dest = (Plane *)&raw_dest;
  617. memnew_placement(dest, Plane(p_self->operator Plane()));
  618. return raw_dest;
  619. }
  620. godot_quaternion godotsharp_variant_as_quaternion(const Variant *p_self) {
  621. godot_quaternion raw_dest;
  622. Quaternion *dest = (Quaternion *)&raw_dest;
  623. memnew_placement(dest, Quaternion(p_self->operator Quaternion()));
  624. return raw_dest;
  625. }
  626. godot_aabb godotsharp_variant_as_aabb(const Variant *p_self) {
  627. godot_aabb raw_dest;
  628. AABB *dest = (AABB *)&raw_dest;
  629. memnew_placement(dest, AABB(p_self->operator ::AABB()));
  630. return raw_dest;
  631. }
  632. godot_basis godotsharp_variant_as_basis(const Variant *p_self) {
  633. godot_basis raw_dest;
  634. Basis *dest = (Basis *)&raw_dest;
  635. memnew_placement(dest, Basis(p_self->operator Basis()));
  636. return raw_dest;
  637. }
  638. godot_transform3d godotsharp_variant_as_transform3d(const Variant *p_self) {
  639. godot_transform3d raw_dest;
  640. Transform3D *dest = (Transform3D *)&raw_dest;
  641. memnew_placement(dest, Transform3D(p_self->operator Transform3D()));
  642. return raw_dest;
  643. }
  644. godot_projection godotsharp_variant_as_projection(const Variant *p_self) {
  645. godot_projection raw_dest;
  646. Projection *dest = (Projection *)&raw_dest;
  647. memnew_placement(dest, Projection(p_self->operator Projection()));
  648. return raw_dest;
  649. }
  650. godot_color godotsharp_variant_as_color(const Variant *p_self) {
  651. godot_color raw_dest;
  652. Color *dest = (Color *)&raw_dest;
  653. memnew_placement(dest, Color(p_self->operator Color()));
  654. return raw_dest;
  655. }
  656. godot_string_name godotsharp_variant_as_string_name(const Variant *p_self) {
  657. godot_string_name raw_dest;
  658. StringName *dest = (StringName *)&raw_dest;
  659. memnew_placement(dest, StringName(p_self->operator StringName()));
  660. return raw_dest;
  661. }
  662. godot_node_path godotsharp_variant_as_node_path(const Variant *p_self) {
  663. godot_node_path raw_dest;
  664. NodePath *dest = (NodePath *)&raw_dest;
  665. memnew_placement(dest, NodePath(p_self->operator NodePath()));
  666. return raw_dest;
  667. }
  668. godot_rid godotsharp_variant_as_rid(const Variant *p_self) {
  669. godot_rid raw_dest;
  670. RID *dest = (RID *)&raw_dest;
  671. memnew_placement(dest, RID(p_self->operator ::RID()));
  672. return raw_dest;
  673. }
  674. godot_callable godotsharp_variant_as_callable(const Variant *p_self) {
  675. godot_callable raw_dest;
  676. Callable *dest = (Callable *)&raw_dest;
  677. memnew_placement(dest, Callable(p_self->operator Callable()));
  678. return raw_dest;
  679. }
  680. godot_signal godotsharp_variant_as_signal(const Variant *p_self) {
  681. godot_signal raw_dest;
  682. Signal *dest = (Signal *)&raw_dest;
  683. memnew_placement(dest, Signal(p_self->operator Signal()));
  684. return raw_dest;
  685. }
  686. godot_dictionary godotsharp_variant_as_dictionary(const Variant *p_self) {
  687. godot_dictionary raw_dest;
  688. Dictionary *dest = (Dictionary *)&raw_dest;
  689. memnew_placement(dest, Dictionary(p_self->operator Dictionary()));
  690. return raw_dest;
  691. }
  692. godot_array godotsharp_variant_as_array(const Variant *p_self) {
  693. godot_array raw_dest;
  694. Array *dest = (Array *)&raw_dest;
  695. memnew_placement(dest, Array(p_self->operator Array()));
  696. return raw_dest;
  697. }
  698. godot_packed_array godotsharp_variant_as_packed_byte_array(const Variant *p_self) {
  699. godot_packed_array raw_dest;
  700. PackedByteArray *dest = (PackedByteArray *)&raw_dest;
  701. memnew_placement(dest, PackedByteArray(p_self->operator PackedByteArray()));
  702. return raw_dest;
  703. }
  704. godot_packed_array godotsharp_variant_as_packed_int32_array(const Variant *p_self) {
  705. godot_packed_array raw_dest;
  706. PackedInt32Array *dest = (PackedInt32Array *)&raw_dest;
  707. memnew_placement(dest, PackedInt32Array(p_self->operator PackedInt32Array()));
  708. return raw_dest;
  709. }
  710. godot_packed_array godotsharp_variant_as_packed_int64_array(const Variant *p_self) {
  711. godot_packed_array raw_dest;
  712. PackedInt64Array *dest = (PackedInt64Array *)&raw_dest;
  713. memnew_placement(dest, PackedInt64Array(p_self->operator PackedInt64Array()));
  714. return raw_dest;
  715. }
  716. godot_packed_array godotsharp_variant_as_packed_float32_array(const Variant *p_self) {
  717. godot_packed_array raw_dest;
  718. PackedFloat32Array *dest = (PackedFloat32Array *)&raw_dest;
  719. memnew_placement(dest, PackedFloat32Array(p_self->operator PackedFloat32Array()));
  720. return raw_dest;
  721. }
  722. godot_packed_array godotsharp_variant_as_packed_float64_array(const Variant *p_self) {
  723. godot_packed_array raw_dest;
  724. PackedFloat64Array *dest = (PackedFloat64Array *)&raw_dest;
  725. memnew_placement(dest, PackedFloat64Array(p_self->operator PackedFloat64Array()));
  726. return raw_dest;
  727. }
  728. godot_packed_array godotsharp_variant_as_packed_string_array(const Variant *p_self) {
  729. godot_packed_array raw_dest;
  730. PackedStringArray *dest = (PackedStringArray *)&raw_dest;
  731. memnew_placement(dest, PackedStringArray(p_self->operator PackedStringArray()));
  732. return raw_dest;
  733. }
  734. godot_packed_array godotsharp_variant_as_packed_vector2_array(const Variant *p_self) {
  735. godot_packed_array raw_dest;
  736. PackedVector2Array *dest = (PackedVector2Array *)&raw_dest;
  737. memnew_placement(dest, PackedVector2Array(p_self->operator PackedVector2Array()));
  738. return raw_dest;
  739. }
  740. godot_packed_array godotsharp_variant_as_packed_vector3_array(const Variant *p_self) {
  741. godot_packed_array raw_dest;
  742. PackedVector3Array *dest = (PackedVector3Array *)&raw_dest;
  743. memnew_placement(dest, PackedVector3Array(p_self->operator PackedVector3Array()));
  744. return raw_dest;
  745. }
  746. godot_packed_array godotsharp_variant_as_packed_vector4_array(const Variant *p_self) {
  747. godot_packed_array raw_dest;
  748. PackedVector4Array *dest = (PackedVector4Array *)&raw_dest;
  749. memnew_placement(dest, PackedVector4Array(p_self->operator PackedVector4Array()));
  750. return raw_dest;
  751. }
  752. godot_packed_array godotsharp_variant_as_packed_color_array(const Variant *p_self) {
  753. godot_packed_array raw_dest;
  754. PackedColorArray *dest = (PackedColorArray *)&raw_dest;
  755. memnew_placement(dest, PackedColorArray(p_self->operator PackedColorArray()));
  756. return raw_dest;
  757. }
  758. bool godotsharp_variant_equals(const godot_variant *p_a, const godot_variant *p_b) {
  759. return *reinterpret_cast<const Variant *>(p_a) == *reinterpret_cast<const Variant *>(p_b);
  760. }
  761. // string.h
  762. void godotsharp_string_new_with_utf16_chars(String *r_dest, const char16_t *p_contents) {
  763. memnew_placement(r_dest, String());
  764. r_dest->parse_utf16(p_contents);
  765. }
  766. // string_name.h
  767. void godotsharp_string_name_new_copy(StringName *r_dest, const StringName *p_src) {
  768. memnew_placement(r_dest, StringName(*p_src));
  769. }
  770. // node_path.h
  771. void godotsharp_node_path_new_copy(NodePath *r_dest, const NodePath *p_src) {
  772. memnew_placement(r_dest, NodePath(*p_src));
  773. }
  774. // array.h
  775. void godotsharp_array_new(Array *r_dest) {
  776. memnew_placement(r_dest, Array);
  777. }
  778. void godotsharp_array_new_copy(Array *r_dest, const Array *p_src) {
  779. memnew_placement(r_dest, Array(*p_src));
  780. }
  781. godot_variant *godotsharp_array_ptrw(godot_array *p_self) {
  782. return reinterpret_cast<godot_variant *>(&reinterpret_cast<Array *>(p_self)->operator[](0));
  783. }
  784. // dictionary.h
  785. void godotsharp_dictionary_new(Dictionary *r_dest) {
  786. memnew_placement(r_dest, Dictionary);
  787. }
  788. void godotsharp_dictionary_new_copy(Dictionary *r_dest, const Dictionary *p_src) {
  789. memnew_placement(r_dest, Dictionary(*p_src));
  790. }
  791. // destroy functions
  792. void godotsharp_packed_byte_array_destroy(PackedByteArray *p_self) {
  793. p_self->~PackedByteArray();
  794. }
  795. void godotsharp_packed_int32_array_destroy(PackedInt32Array *p_self) {
  796. p_self->~PackedInt32Array();
  797. }
  798. void godotsharp_packed_int64_array_destroy(PackedInt64Array *p_self) {
  799. p_self->~PackedInt64Array();
  800. }
  801. void godotsharp_packed_float32_array_destroy(PackedFloat32Array *p_self) {
  802. p_self->~PackedFloat32Array();
  803. }
  804. void godotsharp_packed_float64_array_destroy(PackedFloat64Array *p_self) {
  805. p_self->~PackedFloat64Array();
  806. }
  807. void godotsharp_packed_string_array_destroy(PackedStringArray *p_self) {
  808. p_self->~PackedStringArray();
  809. }
  810. void godotsharp_packed_vector2_array_destroy(PackedVector2Array *p_self) {
  811. p_self->~PackedVector2Array();
  812. }
  813. void godotsharp_packed_vector3_array_destroy(PackedVector3Array *p_self) {
  814. p_self->~PackedVector3Array();
  815. }
  816. void godotsharp_packed_vector4_array_destroy(PackedVector4Array *p_self) {
  817. p_self->~PackedVector4Array();
  818. }
  819. void godotsharp_packed_color_array_destroy(PackedColorArray *p_self) {
  820. p_self->~PackedColorArray();
  821. }
  822. void godotsharp_variant_destroy(Variant *p_self) {
  823. p_self->~Variant();
  824. }
  825. void godotsharp_string_destroy(String *p_self) {
  826. p_self->~String();
  827. }
  828. void godotsharp_string_name_destroy(StringName *p_self) {
  829. p_self->~StringName();
  830. }
  831. void godotsharp_node_path_destroy(NodePath *p_self) {
  832. p_self->~NodePath();
  833. }
  834. void godotsharp_signal_destroy(Signal *p_self) {
  835. p_self->~Signal();
  836. }
  837. void godotsharp_callable_destroy(Callable *p_self) {
  838. p_self->~Callable();
  839. }
  840. void godotsharp_array_destroy(Array *p_self) {
  841. p_self->~Array();
  842. }
  843. void godotsharp_dictionary_destroy(Dictionary *p_self) {
  844. p_self->~Dictionary();
  845. }
  846. // Array
  847. int32_t godotsharp_array_add(Array *p_self, const Variant *p_item) {
  848. p_self->append(*p_item);
  849. return p_self->size();
  850. }
  851. int32_t godotsharp_array_add_range(Array *p_self, const Array *p_collection) {
  852. p_self->append_array(*p_collection);
  853. return p_self->size();
  854. }
  855. int32_t godotsharp_array_binary_search(const Array *p_self, int32_t p_index, int32_t p_length, const Variant *p_value) {
  856. ERR_FAIL_COND_V(p_index < 0, -1);
  857. ERR_FAIL_COND_V(p_length < 0, -1);
  858. ERR_FAIL_COND_V(p_self->size() - p_index < p_length, -1);
  859. const Variant &value = *p_value;
  860. const Array &array = *p_self;
  861. int lo = p_index;
  862. int hi = p_index + p_length - 1;
  863. while (lo <= hi) {
  864. int mid = lo + ((hi - lo) >> 1);
  865. const Variant &mid_item = array[mid];
  866. if (mid_item == value) {
  867. return mid;
  868. }
  869. if (mid_item < value) {
  870. lo = mid + 1;
  871. } else {
  872. hi = mid - 1;
  873. }
  874. }
  875. return ~lo;
  876. }
  877. void godotsharp_array_duplicate(const Array *p_self, bool p_deep, Array *r_dest) {
  878. memnew_placement(r_dest, Array(p_self->duplicate(p_deep)));
  879. }
  880. void godotsharp_array_fill(Array *p_self, const Variant *p_value) {
  881. p_self->fill(*p_value);
  882. }
  883. int32_t godotsharp_array_index_of(const Array *p_self, const Variant *p_item, int32_t p_index = 0) {
  884. return p_self->find(*p_item, p_index);
  885. }
  886. void godotsharp_array_insert(Array *p_self, int32_t p_index, const Variant *p_item) {
  887. p_self->insert(p_index, *p_item);
  888. }
  889. int32_t godotsharp_array_last_index_of(const Array *p_self, const Variant *p_item, int32_t p_index) {
  890. return p_self->rfind(*p_item, p_index);
  891. }
  892. void godotsharp_array_make_read_only(Array *p_self) {
  893. p_self->make_read_only();
  894. }
  895. void godotsharp_array_max(const Array *p_self, Variant *r_value) {
  896. *r_value = p_self->max();
  897. }
  898. void godotsharp_array_min(const Array *p_self, Variant *r_value) {
  899. *r_value = p_self->min();
  900. }
  901. void godotsharp_array_pick_random(const Array *p_self, Variant *r_value) {
  902. *r_value = p_self->pick_random();
  903. }
  904. bool godotsharp_array_recursive_equal(const Array *p_self, const Array *p_other) {
  905. return p_self->recursive_equal(*p_other, 0);
  906. }
  907. void godotsharp_array_remove_at(Array *p_self, int32_t p_index) {
  908. p_self->remove_at(p_index);
  909. }
  910. int32_t godotsharp_array_resize(Array *p_self, int32_t p_new_size) {
  911. return (int32_t)p_self->resize(p_new_size);
  912. }
  913. void godotsharp_array_reverse(Array *p_self) {
  914. p_self->reverse();
  915. }
  916. void godotsharp_array_shuffle(Array *p_self) {
  917. p_self->shuffle();
  918. }
  919. void godotsharp_array_slice(Array *p_self, int32_t p_start, int32_t p_end, int32_t p_step, bool p_deep, Array *r_dest) {
  920. memnew_placement(r_dest, Array(p_self->slice(p_start, p_end, p_step, p_deep)));
  921. }
  922. void godotsharp_array_sort(Array *p_self) {
  923. p_self->sort();
  924. }
  925. void godotsharp_array_to_string(const Array *p_self, String *r_str) {
  926. *r_str = Variant(*p_self).operator String();
  927. }
  928. // Dictionary
  929. bool godotsharp_dictionary_try_get_value(const Dictionary *p_self, const Variant *p_key, Variant *r_value) {
  930. const Variant *ret = p_self->getptr(*p_key);
  931. if (ret == nullptr) {
  932. memnew_placement(r_value, Variant());
  933. return false;
  934. }
  935. memnew_placement(r_value, Variant(*ret));
  936. return true;
  937. }
  938. void godotsharp_dictionary_set_value(Dictionary *p_self, const Variant *p_key, const Variant *p_value) {
  939. p_self->operator[](*p_key) = *p_value;
  940. }
  941. void godotsharp_dictionary_keys(const Dictionary *p_self, Array *r_dest) {
  942. memnew_placement(r_dest, Array(p_self->keys()));
  943. }
  944. void godotsharp_dictionary_values(const Dictionary *p_self, Array *r_dest) {
  945. memnew_placement(r_dest, Array(p_self->values()));
  946. }
  947. int32_t godotsharp_dictionary_count(const Dictionary *p_self) {
  948. return p_self->size();
  949. }
  950. void godotsharp_dictionary_key_value_pair_at(const Dictionary *p_self, int32_t p_index, Variant *r_key, Variant *r_value) {
  951. memnew_placement(r_key, Variant(p_self->get_key_at_index(p_index)));
  952. memnew_placement(r_value, Variant(p_self->get_value_at_index(p_index)));
  953. }
  954. void godotsharp_dictionary_add(Dictionary *p_self, const Variant *p_key, const Variant *p_value) {
  955. p_self->operator[](*p_key) = *p_value;
  956. }
  957. void godotsharp_dictionary_clear(Dictionary *p_self) {
  958. p_self->clear();
  959. }
  960. bool godotsharp_dictionary_contains_key(const Dictionary *p_self, const Variant *p_key) {
  961. return p_self->has(*p_key);
  962. }
  963. void godotsharp_dictionary_duplicate(const Dictionary *p_self, bool p_deep, Dictionary *r_dest) {
  964. memnew_placement(r_dest, Dictionary(p_self->duplicate(p_deep)));
  965. }
  966. void godotsharp_dictionary_merge(Dictionary *p_self, const Dictionary *p_dictionary, bool p_overwrite) {
  967. p_self->merge(*p_dictionary, p_overwrite);
  968. }
  969. bool godotsharp_dictionary_recursive_equal(const Dictionary *p_self, const Dictionary *p_other) {
  970. return p_self->recursive_equal(*p_other, 0);
  971. }
  972. bool godotsharp_dictionary_remove_key(Dictionary *p_self, const Variant *p_key) {
  973. return p_self->erase(*p_key);
  974. }
  975. void godotsharp_dictionary_make_read_only(Dictionary *p_self) {
  976. p_self->make_read_only();
  977. }
  978. void godotsharp_dictionary_to_string(const Dictionary *p_self, String *r_str) {
  979. *r_str = Variant(*p_self).operator String();
  980. }
  981. void godotsharp_string_simplify_path(const String *p_self, String *r_simplified_path) {
  982. memnew_placement(r_simplified_path, String(p_self->simplify_path()));
  983. }
  984. void godotsharp_string_to_camel_case(const String *p_self, String *r_camel_case) {
  985. memnew_placement(r_camel_case, String(p_self->to_camel_case()));
  986. }
  987. void godotsharp_string_to_pascal_case(const String *p_self, String *r_pascal_case) {
  988. memnew_placement(r_pascal_case, String(p_self->to_pascal_case()));
  989. }
  990. void godotsharp_string_to_snake_case(const String *p_self, String *r_snake_case) {
  991. memnew_placement(r_snake_case, String(p_self->to_snake_case()));
  992. }
  993. void godotsharp_node_path_get_as_property_path(const NodePath *p_ptr, NodePath *r_dest) {
  994. memnew_placement(r_dest, NodePath(p_ptr->get_as_property_path()));
  995. }
  996. void godotsharp_node_path_get_concatenated_names(const NodePath *p_self, String *r_subnames) {
  997. memnew_placement(r_subnames, String(p_self->get_concatenated_names()));
  998. }
  999. void godotsharp_node_path_get_concatenated_subnames(const NodePath *p_self, String *r_subnames) {
  1000. memnew_placement(r_subnames, String(p_self->get_concatenated_subnames()));
  1001. }
  1002. void godotsharp_node_path_get_name(const NodePath *p_self, uint32_t p_idx, String *r_name) {
  1003. memnew_placement(r_name, String(p_self->get_name(p_idx)));
  1004. }
  1005. int32_t godotsharp_node_path_get_name_count(const NodePath *p_self) {
  1006. return p_self->get_name_count();
  1007. }
  1008. void godotsharp_node_path_get_subname(const NodePath *p_self, uint32_t p_idx, String *r_subname) {
  1009. memnew_placement(r_subname, String(p_self->get_subname(p_idx)));
  1010. }
  1011. int32_t godotsharp_node_path_get_subname_count(const NodePath *p_self) {
  1012. return p_self->get_subname_count();
  1013. }
  1014. bool godotsharp_node_path_is_absolute(const NodePath *p_self) {
  1015. return p_self->is_absolute();
  1016. }
  1017. bool godotsharp_node_path_equals(const NodePath *p_self, const NodePath *p_other) {
  1018. return *p_self == *p_other;
  1019. }
  1020. int godotsharp_node_path_hash(const NodePath *p_self) {
  1021. return p_self->hash();
  1022. }
  1023. void godotsharp_randomize() {
  1024. Math::randomize();
  1025. }
  1026. uint32_t godotsharp_randi() {
  1027. return Math::rand();
  1028. }
  1029. float godotsharp_randf() {
  1030. return Math::randf();
  1031. }
  1032. int32_t godotsharp_randi_range(int32_t p_from, int32_t p_to) {
  1033. return Math::random(p_from, p_to);
  1034. }
  1035. double godotsharp_randf_range(double p_from, double p_to) {
  1036. return Math::random(p_from, p_to);
  1037. }
  1038. double godotsharp_randfn(double p_mean, double p_deviation) {
  1039. return Math::randfn(p_mean, p_deviation);
  1040. }
  1041. void godotsharp_seed(uint64_t p_seed) {
  1042. Math::seed(p_seed);
  1043. }
  1044. uint32_t godotsharp_rand_from_seed(uint64_t p_seed, uint64_t *r_new_seed) {
  1045. uint32_t ret = Math::rand_from_seed(&p_seed);
  1046. *r_new_seed = p_seed;
  1047. return ret;
  1048. }
  1049. void godotsharp_weakref(Object *p_ptr, Ref<RefCounted> *r_weak_ref) {
  1050. if (!p_ptr) {
  1051. return;
  1052. }
  1053. Ref<WeakRef> wref;
  1054. RefCounted *rc = Object::cast_to<RefCounted>(p_ptr);
  1055. if (rc) {
  1056. Ref<RefCounted> r = rc;
  1057. if (!r.is_valid()) {
  1058. return;
  1059. }
  1060. wref.instantiate();
  1061. wref->set_ref(r);
  1062. } else {
  1063. wref.instantiate();
  1064. wref->set_obj(p_ptr);
  1065. }
  1066. memnew_placement(r_weak_ref, Ref<RefCounted>(wref));
  1067. }
  1068. void godotsharp_print(const godot_string *p_what) {
  1069. print_line(*reinterpret_cast<const String *>(p_what));
  1070. }
  1071. void godotsharp_print_rich(const godot_string *p_what) {
  1072. print_line_rich(*reinterpret_cast<const String *>(p_what));
  1073. }
  1074. void godotsharp_printerr(const godot_string *p_what) {
  1075. print_error(*reinterpret_cast<const String *>(p_what));
  1076. }
  1077. void godotsharp_printt(const godot_string *p_what) {
  1078. print_line(*reinterpret_cast<const String *>(p_what));
  1079. }
  1080. void godotsharp_prints(const godot_string *p_what) {
  1081. print_line(*reinterpret_cast<const String *>(p_what));
  1082. }
  1083. void godotsharp_printraw(const godot_string *p_what) {
  1084. OS::get_singleton()->print("%s", reinterpret_cast<const String *>(p_what)->utf8().get_data());
  1085. }
  1086. void godotsharp_err_print_error(const godot_string *p_function, const godot_string *p_file, int32_t p_line, const godot_string *p_error, const godot_string *p_message, bool p_editor_notify, ErrorHandlerType p_type) {
  1087. _err_print_error(
  1088. reinterpret_cast<const String *>(p_function)->utf8().get_data(),
  1089. reinterpret_cast<const String *>(p_file)->utf8().get_data(),
  1090. p_line,
  1091. reinterpret_cast<const String *>(p_error)->utf8().get_data(),
  1092. reinterpret_cast<const String *>(p_message)->utf8().get_data(),
  1093. p_editor_notify, p_type);
  1094. }
  1095. void godotsharp_var_to_str(const godot_variant *p_var, godot_string *r_ret) {
  1096. const Variant &var = *reinterpret_cast<const Variant *>(p_var);
  1097. String &vars = *memnew_placement(r_ret, String);
  1098. VariantWriter::write_to_string(var, vars);
  1099. }
  1100. void godotsharp_str_to_var(const godot_string *p_str, godot_variant *r_ret) {
  1101. Variant ret;
  1102. VariantParser::StreamString ss;
  1103. ss.s = *reinterpret_cast<const String *>(p_str);
  1104. String errs;
  1105. int line;
  1106. Error err = VariantParser::parse(&ss, ret, errs, line);
  1107. if (err != OK) {
  1108. String err_str = "Parse error at line " + itos(line) + ": " + errs + ".";
  1109. ERR_PRINT(err_str);
  1110. ret = err_str;
  1111. }
  1112. memnew_placement(r_ret, Variant(ret));
  1113. }
  1114. void godotsharp_var_to_bytes(const godot_variant *p_var, bool p_full_objects, godot_packed_array *r_bytes) {
  1115. const Variant &var = *reinterpret_cast<const Variant *>(p_var);
  1116. PackedByteArray &bytes = *memnew_placement(r_bytes, PackedByteArray);
  1117. int len;
  1118. Error err = encode_variant(var, nullptr, len, p_full_objects);
  1119. ERR_FAIL_COND_MSG(err != OK, "Unexpected error encoding variable to bytes, likely unserializable type found (Object or RID).");
  1120. bytes.resize(len);
  1121. encode_variant(var, bytes.ptrw(), len, p_full_objects);
  1122. }
  1123. void godotsharp_bytes_to_var(const godot_packed_array *p_bytes, bool p_allow_objects, godot_variant *r_ret) {
  1124. const PackedByteArray *bytes = reinterpret_cast<const PackedByteArray *>(p_bytes);
  1125. Variant ret;
  1126. Error err = decode_variant(ret, bytes->ptr(), bytes->size(), nullptr, p_allow_objects);
  1127. if (err != OK) {
  1128. ret = RTR("Not enough bytes for decoding bytes, or invalid format.");
  1129. }
  1130. memnew_placement(r_ret, Variant(ret));
  1131. }
  1132. int godotsharp_hash(const godot_variant *p_var) {
  1133. return reinterpret_cast<const Variant *>(p_var)->hash();
  1134. }
  1135. void godotsharp_convert(const godot_variant *p_what, int32_t p_type, godot_variant *r_ret) {
  1136. const Variant *args[1] = { reinterpret_cast<const Variant *>(p_what) };
  1137. Callable::CallError ce;
  1138. Variant ret;
  1139. Variant::construct(Variant::Type(p_type), ret, args, 1, ce);
  1140. if (ce.error != Callable::CallError::CALL_OK) {
  1141. memnew_placement(r_ret, Variant);
  1142. ERR_FAIL_MSG("Unable to convert parameter from '" +
  1143. Variant::get_type_name(reinterpret_cast<const Variant *>(p_what)->get_type()) +
  1144. "' to '" + Variant::get_type_name(Variant::Type(p_type)) + "'.");
  1145. }
  1146. memnew_placement(r_ret, Variant(ret));
  1147. }
  1148. Object *godotsharp_instance_from_id(uint64_t p_instance_id) {
  1149. return ObjectDB::get_instance(ObjectID(p_instance_id));
  1150. }
  1151. void godotsharp_object_to_string(Object *p_ptr, godot_string *r_str) {
  1152. #ifdef DEBUG_ENABLED
  1153. // Cannot happen in C#; would get an ObjectDisposedException instead.
  1154. CRASH_COND(p_ptr == nullptr);
  1155. #endif
  1156. // Can't call 'Object::to_string()' here, as that can end up calling 'ToString' again resulting in an endless circular loop.
  1157. memnew_placement(r_str,
  1158. String("<" + p_ptr->get_class() + "#" + itos(p_ptr->get_instance_id()) + ">"));
  1159. }
  1160. #ifdef __cplusplus
  1161. }
  1162. #endif
  1163. // The order in this array must match the declaration order of
  1164. // the methods in 'GodotSharp/Core/NativeInterop/NativeFuncs.cs'.
  1165. static const void *unmanaged_callbacks[]{
  1166. (void *)godotsharp_dotnet_module_is_initialized,
  1167. (void *)godotsharp_method_bind_get_method,
  1168. (void *)godotsharp_method_bind_get_method_with_compatibility,
  1169. (void *)godotsharp_get_class_constructor,
  1170. (void *)godotsharp_engine_get_singleton,
  1171. (void *)godotsharp_stack_info_vector_resize,
  1172. (void *)godotsharp_stack_info_vector_destroy,
  1173. (void *)godotsharp_internal_editor_file_system_update_file,
  1174. (void *)godotsharp_internal_script_debugger_send_error,
  1175. (void *)godotsharp_internal_script_debugger_is_active,
  1176. (void *)godotsharp_internal_object_get_associated_gchandle,
  1177. (void *)godotsharp_internal_object_disposed,
  1178. (void *)godotsharp_internal_refcounted_disposed,
  1179. (void *)godotsharp_internal_signal_awaiter_connect,
  1180. (void *)godotsharp_internal_tie_native_managed_to_unmanaged,
  1181. (void *)godotsharp_internal_tie_user_managed_to_unmanaged,
  1182. (void *)godotsharp_internal_tie_managed_to_unmanaged_with_pre_setup,
  1183. (void *)godotsharp_internal_unmanaged_get_script_instance_managed,
  1184. (void *)godotsharp_internal_unmanaged_get_instance_binding_managed,
  1185. (void *)godotsharp_internal_unmanaged_instance_binding_create_managed,
  1186. (void *)godotsharp_internal_new_csharp_script,
  1187. (void *)godotsharp_internal_script_load,
  1188. (void *)godotsharp_internal_reload_registered_script,
  1189. (void *)godotsharp_array_filter_godot_objects_by_native,
  1190. (void *)godotsharp_array_filter_godot_objects_by_non_native,
  1191. (void *)godotsharp_ref_new_from_ref_counted_ptr,
  1192. (void *)godotsharp_ref_destroy,
  1193. (void *)godotsharp_string_name_new_from_string,
  1194. (void *)godotsharp_node_path_new_from_string,
  1195. (void *)godotsharp_string_name_as_string,
  1196. (void *)godotsharp_node_path_as_string,
  1197. (void *)godotsharp_packed_byte_array_new_mem_copy,
  1198. (void *)godotsharp_packed_int32_array_new_mem_copy,
  1199. (void *)godotsharp_packed_int64_array_new_mem_copy,
  1200. (void *)godotsharp_packed_float32_array_new_mem_copy,
  1201. (void *)godotsharp_packed_float64_array_new_mem_copy,
  1202. (void *)godotsharp_packed_vector2_array_new_mem_copy,
  1203. (void *)godotsharp_packed_vector3_array_new_mem_copy,
  1204. (void *)godotsharp_packed_vector4_array_new_mem_copy,
  1205. (void *)godotsharp_packed_color_array_new_mem_copy,
  1206. (void *)godotsharp_packed_string_array_add,
  1207. (void *)godotsharp_callable_new_with_delegate,
  1208. (void *)godotsharp_callable_get_data_for_marshalling,
  1209. (void *)godotsharp_callable_call,
  1210. (void *)godotsharp_callable_call_deferred,
  1211. (void *)godotsharp_color_from_ok_hsl,
  1212. (void *)godotsharp_method_bind_ptrcall,
  1213. (void *)godotsharp_method_bind_call,
  1214. (void *)godotsharp_variant_new_string_name,
  1215. (void *)godotsharp_variant_new_copy,
  1216. (void *)godotsharp_variant_new_node_path,
  1217. (void *)godotsharp_variant_new_object,
  1218. (void *)godotsharp_variant_new_transform2d,
  1219. (void *)godotsharp_variant_new_basis,
  1220. (void *)godotsharp_variant_new_transform3d,
  1221. (void *)godotsharp_variant_new_projection,
  1222. (void *)godotsharp_variant_new_aabb,
  1223. (void *)godotsharp_variant_new_dictionary,
  1224. (void *)godotsharp_variant_new_array,
  1225. (void *)godotsharp_variant_new_packed_byte_array,
  1226. (void *)godotsharp_variant_new_packed_int32_array,
  1227. (void *)godotsharp_variant_new_packed_int64_array,
  1228. (void *)godotsharp_variant_new_packed_float32_array,
  1229. (void *)godotsharp_variant_new_packed_float64_array,
  1230. (void *)godotsharp_variant_new_packed_string_array,
  1231. (void *)godotsharp_variant_new_packed_vector2_array,
  1232. (void *)godotsharp_variant_new_packed_vector3_array,
  1233. (void *)godotsharp_variant_new_packed_vector4_array,
  1234. (void *)godotsharp_variant_new_packed_color_array,
  1235. (void *)godotsharp_variant_as_bool,
  1236. (void *)godotsharp_variant_as_int,
  1237. (void *)godotsharp_variant_as_float,
  1238. (void *)godotsharp_variant_as_string,
  1239. (void *)godotsharp_variant_as_vector2,
  1240. (void *)godotsharp_variant_as_vector2i,
  1241. (void *)godotsharp_variant_as_rect2,
  1242. (void *)godotsharp_variant_as_rect2i,
  1243. (void *)godotsharp_variant_as_vector3,
  1244. (void *)godotsharp_variant_as_vector3i,
  1245. (void *)godotsharp_variant_as_transform2d,
  1246. (void *)godotsharp_variant_as_vector4,
  1247. (void *)godotsharp_variant_as_vector4i,
  1248. (void *)godotsharp_variant_as_plane,
  1249. (void *)godotsharp_variant_as_quaternion,
  1250. (void *)godotsharp_variant_as_aabb,
  1251. (void *)godotsharp_variant_as_basis,
  1252. (void *)godotsharp_variant_as_transform3d,
  1253. (void *)godotsharp_variant_as_projection,
  1254. (void *)godotsharp_variant_as_color,
  1255. (void *)godotsharp_variant_as_string_name,
  1256. (void *)godotsharp_variant_as_node_path,
  1257. (void *)godotsharp_variant_as_rid,
  1258. (void *)godotsharp_variant_as_callable,
  1259. (void *)godotsharp_variant_as_signal,
  1260. (void *)godotsharp_variant_as_dictionary,
  1261. (void *)godotsharp_variant_as_array,
  1262. (void *)godotsharp_variant_as_packed_byte_array,
  1263. (void *)godotsharp_variant_as_packed_int32_array,
  1264. (void *)godotsharp_variant_as_packed_int64_array,
  1265. (void *)godotsharp_variant_as_packed_float32_array,
  1266. (void *)godotsharp_variant_as_packed_float64_array,
  1267. (void *)godotsharp_variant_as_packed_string_array,
  1268. (void *)godotsharp_variant_as_packed_vector2_array,
  1269. (void *)godotsharp_variant_as_packed_vector3_array,
  1270. (void *)godotsharp_variant_as_packed_vector4_array,
  1271. (void *)godotsharp_variant_as_packed_color_array,
  1272. (void *)godotsharp_variant_equals,
  1273. (void *)godotsharp_string_new_with_utf16_chars,
  1274. (void *)godotsharp_string_name_new_copy,
  1275. (void *)godotsharp_node_path_new_copy,
  1276. (void *)godotsharp_array_new,
  1277. (void *)godotsharp_array_new_copy,
  1278. (void *)godotsharp_array_ptrw,
  1279. (void *)godotsharp_dictionary_new,
  1280. (void *)godotsharp_dictionary_new_copy,
  1281. (void *)godotsharp_packed_byte_array_destroy,
  1282. (void *)godotsharp_packed_int32_array_destroy,
  1283. (void *)godotsharp_packed_int64_array_destroy,
  1284. (void *)godotsharp_packed_float32_array_destroy,
  1285. (void *)godotsharp_packed_float64_array_destroy,
  1286. (void *)godotsharp_packed_string_array_destroy,
  1287. (void *)godotsharp_packed_vector2_array_destroy,
  1288. (void *)godotsharp_packed_vector3_array_destroy,
  1289. (void *)godotsharp_packed_vector4_array_destroy,
  1290. (void *)godotsharp_packed_color_array_destroy,
  1291. (void *)godotsharp_variant_destroy,
  1292. (void *)godotsharp_string_destroy,
  1293. (void *)godotsharp_string_name_destroy,
  1294. (void *)godotsharp_node_path_destroy,
  1295. (void *)godotsharp_signal_destroy,
  1296. (void *)godotsharp_callable_destroy,
  1297. (void *)godotsharp_array_destroy,
  1298. (void *)godotsharp_dictionary_destroy,
  1299. (void *)godotsharp_array_add,
  1300. (void *)godotsharp_array_add_range,
  1301. (void *)godotsharp_array_binary_search,
  1302. (void *)godotsharp_array_duplicate,
  1303. (void *)godotsharp_array_fill,
  1304. (void *)godotsharp_array_index_of,
  1305. (void *)godotsharp_array_insert,
  1306. (void *)godotsharp_array_last_index_of,
  1307. (void *)godotsharp_array_make_read_only,
  1308. (void *)godotsharp_array_max,
  1309. (void *)godotsharp_array_min,
  1310. (void *)godotsharp_array_pick_random,
  1311. (void *)godotsharp_array_recursive_equal,
  1312. (void *)godotsharp_array_remove_at,
  1313. (void *)godotsharp_array_resize,
  1314. (void *)godotsharp_array_reverse,
  1315. (void *)godotsharp_array_shuffle,
  1316. (void *)godotsharp_array_slice,
  1317. (void *)godotsharp_array_sort,
  1318. (void *)godotsharp_array_to_string,
  1319. (void *)godotsharp_dictionary_try_get_value,
  1320. (void *)godotsharp_dictionary_set_value,
  1321. (void *)godotsharp_dictionary_keys,
  1322. (void *)godotsharp_dictionary_values,
  1323. (void *)godotsharp_dictionary_count,
  1324. (void *)godotsharp_dictionary_key_value_pair_at,
  1325. (void *)godotsharp_dictionary_add,
  1326. (void *)godotsharp_dictionary_clear,
  1327. (void *)godotsharp_dictionary_contains_key,
  1328. (void *)godotsharp_dictionary_duplicate,
  1329. (void *)godotsharp_dictionary_merge,
  1330. (void *)godotsharp_dictionary_recursive_equal,
  1331. (void *)godotsharp_dictionary_remove_key,
  1332. (void *)godotsharp_dictionary_make_read_only,
  1333. (void *)godotsharp_dictionary_to_string,
  1334. (void *)godotsharp_string_simplify_path,
  1335. (void *)godotsharp_string_to_camel_case,
  1336. (void *)godotsharp_string_to_pascal_case,
  1337. (void *)godotsharp_string_to_snake_case,
  1338. (void *)godotsharp_node_path_get_as_property_path,
  1339. (void *)godotsharp_node_path_get_concatenated_names,
  1340. (void *)godotsharp_node_path_get_concatenated_subnames,
  1341. (void *)godotsharp_node_path_get_name,
  1342. (void *)godotsharp_node_path_get_name_count,
  1343. (void *)godotsharp_node_path_get_subname,
  1344. (void *)godotsharp_node_path_get_subname_count,
  1345. (void *)godotsharp_node_path_is_absolute,
  1346. (void *)godotsharp_node_path_equals,
  1347. (void *)godotsharp_node_path_hash,
  1348. (void *)godotsharp_bytes_to_var,
  1349. (void *)godotsharp_convert,
  1350. (void *)godotsharp_hash,
  1351. (void *)godotsharp_instance_from_id,
  1352. (void *)godotsharp_print,
  1353. (void *)godotsharp_print_rich,
  1354. (void *)godotsharp_printerr,
  1355. (void *)godotsharp_printraw,
  1356. (void *)godotsharp_prints,
  1357. (void *)godotsharp_printt,
  1358. (void *)godotsharp_randf,
  1359. (void *)godotsharp_randi,
  1360. (void *)godotsharp_randomize,
  1361. (void *)godotsharp_randf_range,
  1362. (void *)godotsharp_randfn,
  1363. (void *)godotsharp_randi_range,
  1364. (void *)godotsharp_rand_from_seed,
  1365. (void *)godotsharp_seed,
  1366. (void *)godotsharp_weakref,
  1367. (void *)godotsharp_str_to_var,
  1368. (void *)godotsharp_var_to_bytes,
  1369. (void *)godotsharp_var_to_str,
  1370. (void *)godotsharp_err_print_error,
  1371. (void *)godotsharp_object_to_string,
  1372. };
  1373. const void **godotsharp::get_runtime_interop_funcs(int32_t &r_size) {
  1374. r_size = sizeof(unmanaged_callbacks);
  1375. return unmanaged_callbacks;
  1376. }