2017-10-03 05:24:00 +08:00
|
|
|
/*************************************************************************/
|
|
|
|
/* gd_mono_utils.cpp */
|
|
|
|
/*************************************************************************/
|
|
|
|
/* This file is part of: */
|
|
|
|
/* GODOT ENGINE */
|
|
|
|
/* https://godotengine.org */
|
|
|
|
/*************************************************************************/
|
2019-01-01 19:53:14 +08:00
|
|
|
/* Copyright (c) 2007-2019 Juan Linietsky, Ariel Manzur. */
|
|
|
|
/* Copyright (c) 2014-2019 Godot Engine contributors (cf. AUTHORS.md) */
|
2017-10-03 05:24:00 +08:00
|
|
|
/* */
|
|
|
|
/* Permission is hereby granted, free of charge, to any person obtaining */
|
|
|
|
/* a copy of this software and associated documentation files (the */
|
|
|
|
/* "Software"), to deal in the Software without restriction, including */
|
|
|
|
/* without limitation the rights to use, copy, modify, merge, publish, */
|
|
|
|
/* distribute, sublicense, and/or sell copies of the Software, and to */
|
|
|
|
/* permit persons to whom the Software is furnished to do so, subject to */
|
|
|
|
/* the following conditions: */
|
|
|
|
/* */
|
|
|
|
/* The above copyright notice and this permission notice shall be */
|
|
|
|
/* included in all copies or substantial portions of the Software. */
|
|
|
|
/* */
|
|
|
|
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
|
|
|
|
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
|
|
|
|
/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
|
|
|
|
/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
|
|
|
|
/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
|
|
|
|
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
|
|
|
|
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
|
|
|
|
/*************************************************************************/
|
2018-01-05 07:50:27 +08:00
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
#include "gd_mono_utils.h"
|
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
#include <mono/metadata/exception.h>
|
|
|
|
|
2018-09-12 00:13:45 +08:00
|
|
|
#include "core/os/dir_access.h"
|
|
|
|
#include "core/os/os.h"
|
|
|
|
#include "core/project_settings.h"
|
|
|
|
#include "core/reference.h"
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2019-07-25 05:13:24 +08:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
#include "editor/script_editor_debugger.h"
|
|
|
|
#endif
|
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
#include "../csharp_script.h"
|
2018-06-27 03:03:42 +08:00
|
|
|
#include "../utils/macros.h"
|
2019-02-05 03:39:02 +08:00
|
|
|
#include "../utils/mutex_utils.h"
|
2017-10-03 05:24:00 +08:00
|
|
|
#include "gd_mono.h"
|
|
|
|
#include "gd_mono_class.h"
|
|
|
|
#include "gd_mono_marshal.h"
|
|
|
|
|
|
|
|
namespace GDMonoUtils {
|
|
|
|
|
|
|
|
MonoCache mono_cache;
|
|
|
|
|
2019-08-09 09:39:45 +08:00
|
|
|
#define CACHE_AND_CHECK(m_var, m_val) \
|
|
|
|
{ \
|
|
|
|
CRASH_COND(m_var != NULL); \
|
|
|
|
m_var = m_val; \
|
|
|
|
ERR_FAIL_COND_MSG(!m_var, "Mono Cache: Member " #m_var " is null."); \
|
2017-10-03 05:24:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#define CACHE_CLASS_AND_CHECK(m_class, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.class_##m_class, m_val)
|
|
|
|
#define CACHE_NS_CLASS_AND_CHECK(m_ns, m_class, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.class_##m_ns##_##m_class, m_val)
|
|
|
|
#define CACHE_RAW_MONO_CLASS_AND_CHECK(m_class, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.rawclass_##m_class, m_val)
|
|
|
|
#define CACHE_FIELD_AND_CHECK(m_class, m_field, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.field_##m_class##_##m_field, m_val)
|
2018-01-10 00:19:03 +08:00
|
|
|
#define CACHE_METHOD_AND_CHECK(m_class, m_method, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.method_##m_class##_##m_method, m_val)
|
2017-10-03 05:24:00 +08:00
|
|
|
#define CACHE_METHOD_THUNK_AND_CHECK(m_class, m_method, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.methodthunk_##m_class##_##m_method, m_val)
|
2019-03-06 01:52:19 +08:00
|
|
|
#define CACHE_PROPERTY_AND_CHECK(m_class, m_property, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.property_##m_class##_##m_property, m_val)
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2019-05-21 00:34:35 +08:00
|
|
|
void MonoCache::clear_corlib_cache() {
|
|
|
|
|
|
|
|
corlib_cache_updated = false;
|
2017-10-03 05:24:00 +08:00
|
|
|
|
|
|
|
class_MonoObject = NULL;
|
|
|
|
class_bool = NULL;
|
|
|
|
class_int8_t = NULL;
|
|
|
|
class_int16_t = NULL;
|
|
|
|
class_int32_t = NULL;
|
|
|
|
class_int64_t = NULL;
|
|
|
|
class_uint8_t = NULL;
|
|
|
|
class_uint16_t = NULL;
|
|
|
|
class_uint32_t = NULL;
|
|
|
|
class_uint64_t = NULL;
|
|
|
|
class_float = NULL;
|
|
|
|
class_double = NULL;
|
|
|
|
class_String = NULL;
|
|
|
|
class_IntPtr = NULL;
|
|
|
|
|
2019-03-06 01:52:19 +08:00
|
|
|
class_System_Collections_IEnumerable = NULL;
|
|
|
|
class_System_Collections_IDictionary = NULL;
|
|
|
|
|
2018-01-10 00:19:03 +08:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
class_System_Diagnostics_StackTrace = NULL;
|
|
|
|
methodthunk_System_Diagnostics_StackTrace_GetFrames = NULL;
|
|
|
|
method_System_Diagnostics_StackTrace_ctor_bool = NULL;
|
|
|
|
method_System_Diagnostics_StackTrace_ctor_Exception_bool = NULL;
|
|
|
|
#endif
|
|
|
|
|
2018-07-19 05:07:57 +08:00
|
|
|
class_KeyNotFoundException = NULL;
|
2019-05-21 00:34:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void MonoCache::clear_godot_api_cache() {
|
|
|
|
|
|
|
|
godot_api_cache_updated = false;
|
2018-07-19 05:07:57 +08:00
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
rawclass_Dictionary = NULL;
|
|
|
|
|
|
|
|
class_Vector2 = NULL;
|
|
|
|
class_Rect2 = NULL;
|
|
|
|
class_Transform2D = NULL;
|
|
|
|
class_Vector3 = NULL;
|
|
|
|
class_Basis = NULL;
|
|
|
|
class_Quat = NULL;
|
|
|
|
class_Transform = NULL;
|
2017-11-17 10:09:00 +08:00
|
|
|
class_AABB = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
class_Color = NULL;
|
|
|
|
class_Plane = NULL;
|
|
|
|
class_NodePath = NULL;
|
|
|
|
class_RID = NULL;
|
|
|
|
class_GodotObject = NULL;
|
2019-05-18 10:14:21 +08:00
|
|
|
class_GodotResource = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
class_Node = NULL;
|
|
|
|
class_Control = NULL;
|
|
|
|
class_Spatial = NULL;
|
|
|
|
class_WeakRef = NULL;
|
2018-07-19 05:07:57 +08:00
|
|
|
class_Array = NULL;
|
|
|
|
class_Dictionary = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
class_MarshalUtils = NULL;
|
2019-07-03 15:44:53 +08:00
|
|
|
class_ISerializationListener = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2018-01-10 00:19:03 +08:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
class_DebuggingUtils = NULL;
|
|
|
|
methodthunk_DebuggingUtils_GetStackFrameInfo = NULL;
|
|
|
|
#endif
|
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
class_ExportAttribute = NULL;
|
|
|
|
field_ExportAttribute_hint = NULL;
|
2017-12-24 10:17:48 +08:00
|
|
|
field_ExportAttribute_hintString = NULL;
|
2018-01-19 01:17:29 +08:00
|
|
|
class_SignalAttribute = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
class_ToolAttribute = NULL;
|
|
|
|
class_RemoteAttribute = NULL;
|
|
|
|
class_SyncAttribute = NULL;
|
|
|
|
class_MasterAttribute = NULL;
|
2018-09-15 03:59:47 +08:00
|
|
|
class_PuppetAttribute = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
class_SlaveAttribute = NULL;
|
2018-05-26 16:30:36 +08:00
|
|
|
class_RemoteSyncAttribute = NULL;
|
|
|
|
class_MasterSyncAttribute = NULL;
|
2018-09-15 03:59:47 +08:00
|
|
|
class_PuppetSyncAttribute = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
class_GodotMethodAttribute = NULL;
|
|
|
|
field_GodotMethodAttribute_methodName = NULL;
|
|
|
|
|
|
|
|
field_GodotObject_ptr = NULL;
|
|
|
|
field_NodePath_ptr = NULL;
|
|
|
|
field_Image_ptr = NULL;
|
|
|
|
field_RID_ptr = NULL;
|
|
|
|
|
2018-09-12 08:41:54 +08:00
|
|
|
methodthunk_GodotObject_Dispose = NULL;
|
2018-07-19 05:07:57 +08:00
|
|
|
methodthunk_Array_GetPtr = NULL;
|
|
|
|
methodthunk_Dictionary_GetPtr = NULL;
|
2017-10-16 09:54:23 +08:00
|
|
|
methodthunk_SignalAwaiter_SignalCallback = NULL;
|
2017-10-03 05:24:00 +08:00
|
|
|
methodthunk_SignalAwaiter_FailureCallback = NULL;
|
|
|
|
methodthunk_GodotTaskScheduler_Activate = NULL;
|
|
|
|
|
2019-05-18 10:14:21 +08:00
|
|
|
// Start of MarshalUtils methods
|
|
|
|
|
2019-03-06 01:52:19 +08:00
|
|
|
methodthunk_MarshalUtils_TypeIsGenericArray = NULL;
|
|
|
|
methodthunk_MarshalUtils_TypeIsGenericDictionary = NULL;
|
2019-05-18 10:14:21 +08:00
|
|
|
|
2019-03-06 04:39:50 +08:00
|
|
|
methodthunk_MarshalUtils_ArrayGetElementType = NULL;
|
|
|
|
methodthunk_MarshalUtils_DictionaryGetKeyValueTypes = NULL;
|
2019-05-18 10:14:21 +08:00
|
|
|
|
|
|
|
methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType = NULL;
|
|
|
|
methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType = NULL;
|
2019-05-22 01:09:00 +08:00
|
|
|
methodthunk_MarshalUtils_GenericIEnumerableIsAssignableFromType_with_info = NULL;
|
|
|
|
methodthunk_MarshalUtils_GenericIDictionaryIsAssignableFromType_with_info = NULL;
|
2019-05-18 10:14:21 +08:00
|
|
|
|
|
|
|
methodthunk_MarshalUtils_MakeGenericArrayType = NULL;
|
|
|
|
methodthunk_MarshalUtils_MakeGenericDictionaryType = NULL;
|
|
|
|
|
2019-03-06 01:52:19 +08:00
|
|
|
methodthunk_MarshalUtils_EnumerableToArray = NULL;
|
|
|
|
methodthunk_MarshalUtils_IDictionaryToDictionary = NULL;
|
2019-05-18 10:14:21 +08:00
|
|
|
methodthunk_MarshalUtils_GenericIDictionaryToDictionary = NULL;
|
|
|
|
|
|
|
|
// End of MarshalUtils methods
|
2019-03-06 01:52:19 +08:00
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
task_scheduler_handle = Ref<MonoGCHandle>();
|
|
|
|
}
|
|
|
|
|
2018-02-22 20:13:51 +08:00
|
|
|
#define GODOT_API_CLASS(m_class) (GDMono::get_singleton()->get_core_api_assembly()->get_class(BINDINGS_NAMESPACE, #m_class))
|
2018-08-25 23:16:16 +08:00
|
|
|
#define GODOT_API_NS_CLAS(m_ns, m_class) (GDMono::get_singleton()->get_core_api_assembly()->get_class(m_ns, #m_class))
|
2017-10-03 05:24:00 +08:00
|
|
|
|
|
|
|
void update_corlib_cache() {
|
|
|
|
|
|
|
|
CACHE_CLASS_AND_CHECK(MonoObject, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_object_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(bool, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_boolean_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(int8_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_sbyte_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(int16_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int16_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(int32_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int32_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(int64_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_int64_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(uint8_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_byte_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(uint16_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint16_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(uint32_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint32_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(uint64_t, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_uint64_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(float, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_single_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(double, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_double_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(String, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_string_class()));
|
|
|
|
CACHE_CLASS_AND_CHECK(IntPtr, GDMono::get_singleton()->get_corlib_assembly()->get_class(mono_get_intptr_class()));
|
2018-01-10 00:19:03 +08:00
|
|
|
|
2019-03-06 01:52:19 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(System_Collections_IEnumerable, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections", "IEnumerable"));
|
|
|
|
CACHE_CLASS_AND_CHECK(System_Collections_IDictionary, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections", "IDictionary"));
|
|
|
|
|
2018-01-10 00:19:03 +08:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
CACHE_CLASS_AND_CHECK(System_Diagnostics_StackTrace, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Diagnostics", "StackTrace"));
|
2018-07-26 03:30:11 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(System_Diagnostics_StackTrace, GetFrames, (StackTrace_GetFrames)CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_thunk("GetFrames"));
|
2018-01-10 00:19:03 +08:00
|
|
|
CACHE_METHOD_AND_CHECK(System_Diagnostics_StackTrace, ctor_bool, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_with_desc("System.Diagnostics.StackTrace:.ctor(bool)", true));
|
|
|
|
CACHE_METHOD_AND_CHECK(System_Diagnostics_StackTrace, ctor_Exception_bool, CACHED_CLASS(System_Diagnostics_StackTrace)->get_method_with_desc("System.Diagnostics.StackTrace:.ctor(System.Exception,bool)", true));
|
|
|
|
#endif
|
2018-01-13 02:23:11 +08:00
|
|
|
|
2018-07-19 05:07:57 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(KeyNotFoundException, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Collections.Generic", "KeyNotFoundException"));
|
|
|
|
|
2018-01-13 02:23:11 +08:00
|
|
|
mono_cache.corlib_cache_updated = true;
|
2017-10-03 05:24:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void update_godot_api_cache() {
|
|
|
|
|
|
|
|
CACHE_CLASS_AND_CHECK(Vector2, GODOT_API_CLASS(Vector2));
|
|
|
|
CACHE_CLASS_AND_CHECK(Rect2, GODOT_API_CLASS(Rect2));
|
|
|
|
CACHE_CLASS_AND_CHECK(Transform2D, GODOT_API_CLASS(Transform2D));
|
|
|
|
CACHE_CLASS_AND_CHECK(Vector3, GODOT_API_CLASS(Vector3));
|
|
|
|
CACHE_CLASS_AND_CHECK(Basis, GODOT_API_CLASS(Basis));
|
|
|
|
CACHE_CLASS_AND_CHECK(Quat, GODOT_API_CLASS(Quat));
|
|
|
|
CACHE_CLASS_AND_CHECK(Transform, GODOT_API_CLASS(Transform));
|
2017-11-17 10:09:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(AABB, GODOT_API_CLASS(AABB));
|
2017-10-03 05:24:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(Color, GODOT_API_CLASS(Color));
|
|
|
|
CACHE_CLASS_AND_CHECK(Plane, GODOT_API_CLASS(Plane));
|
|
|
|
CACHE_CLASS_AND_CHECK(NodePath, GODOT_API_CLASS(NodePath));
|
2018-01-22 21:01:20 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(RID, GODOT_API_CLASS(RID));
|
2017-10-03 05:24:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(GodotObject, GODOT_API_CLASS(Object));
|
2019-05-18 10:14:21 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(GodotResource, GODOT_API_CLASS(Resource));
|
2017-10-03 05:24:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(Node, GODOT_API_CLASS(Node));
|
|
|
|
CACHE_CLASS_AND_CHECK(Control, GODOT_API_CLASS(Control));
|
|
|
|
CACHE_CLASS_AND_CHECK(Spatial, GODOT_API_CLASS(Spatial));
|
|
|
|
CACHE_CLASS_AND_CHECK(WeakRef, GODOT_API_CLASS(WeakRef));
|
2018-08-25 23:16:16 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(Array, GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Array));
|
|
|
|
CACHE_CLASS_AND_CHECK(Dictionary, GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Dictionary));
|
2017-10-03 05:24:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(MarshalUtils, GODOT_API_CLASS(MarshalUtils));
|
2019-07-03 15:44:53 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(ISerializationListener, GODOT_API_CLASS(ISerializationListener));
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2018-01-10 00:19:03 +08:00
|
|
|
#ifdef DEBUG_ENABLED
|
|
|
|
CACHE_CLASS_AND_CHECK(DebuggingUtils, GODOT_API_CLASS(DebuggingUtils));
|
|
|
|
#endif
|
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
// Attributes
|
|
|
|
CACHE_CLASS_AND_CHECK(ExportAttribute, GODOT_API_CLASS(ExportAttribute));
|
|
|
|
CACHE_FIELD_AND_CHECK(ExportAttribute, hint, CACHED_CLASS(ExportAttribute)->get_field("hint"));
|
2017-12-24 10:17:48 +08:00
|
|
|
CACHE_FIELD_AND_CHECK(ExportAttribute, hintString, CACHED_CLASS(ExportAttribute)->get_field("hintString"));
|
2018-01-19 01:17:29 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(SignalAttribute, GODOT_API_CLASS(SignalAttribute));
|
2017-10-03 05:24:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(ToolAttribute, GODOT_API_CLASS(ToolAttribute));
|
|
|
|
CACHE_CLASS_AND_CHECK(RemoteAttribute, GODOT_API_CLASS(RemoteAttribute));
|
|
|
|
CACHE_CLASS_AND_CHECK(SyncAttribute, GODOT_API_CLASS(SyncAttribute));
|
|
|
|
CACHE_CLASS_AND_CHECK(MasterAttribute, GODOT_API_CLASS(MasterAttribute));
|
2018-09-15 03:59:47 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(PuppetAttribute, GODOT_API_CLASS(PuppetAttribute));
|
2017-10-03 05:24:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(SlaveAttribute, GODOT_API_CLASS(SlaveAttribute));
|
2018-05-26 16:30:36 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(RemoteSyncAttribute, GODOT_API_CLASS(RemoteSyncAttribute));
|
|
|
|
CACHE_CLASS_AND_CHECK(MasterSyncAttribute, GODOT_API_CLASS(MasterSyncAttribute));
|
2018-09-15 03:59:47 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(PuppetSyncAttribute, GODOT_API_CLASS(PuppetSyncAttribute));
|
2017-10-03 05:24:00 +08:00
|
|
|
CACHE_CLASS_AND_CHECK(GodotMethodAttribute, GODOT_API_CLASS(GodotMethodAttribute));
|
|
|
|
CACHE_FIELD_AND_CHECK(GodotMethodAttribute, methodName, CACHED_CLASS(GodotMethodAttribute)->get_field("methodName"));
|
|
|
|
|
|
|
|
CACHE_FIELD_AND_CHECK(GodotObject, ptr, CACHED_CLASS(GodotObject)->get_field(BINDINGS_PTR_FIELD));
|
|
|
|
CACHE_FIELD_AND_CHECK(NodePath, ptr, CACHED_CLASS(NodePath)->get_field(BINDINGS_PTR_FIELD));
|
|
|
|
CACHE_FIELD_AND_CHECK(RID, ptr, CACHED_CLASS(RID)->get_field(BINDINGS_PTR_FIELD));
|
|
|
|
|
2018-09-12 08:41:54 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(GodotObject, Dispose, (GodotObject_Dispose)CACHED_CLASS(GodotObject)->get_method_thunk("Dispose", 0));
|
2018-08-25 23:16:16 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(Array, GetPtr, (Array_GetPtr)GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Array)->get_method_thunk("GetPtr", 0));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(Dictionary, GetPtr, (Dictionary_GetPtr)GODOT_API_NS_CLAS(BINDINGS_NAMESPACE_COLLECTIONS, Dictionary)->get_method_thunk("GetPtr", 0));
|
2018-07-26 03:30:11 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(SignalAwaiter, SignalCallback, (SignalAwaiter_SignalCallback)GODOT_API_CLASS(SignalAwaiter)->get_method_thunk("SignalCallback", 1));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(SignalAwaiter, FailureCallback, (SignalAwaiter_FailureCallback)GODOT_API_CLASS(SignalAwaiter)->get_method_thunk("FailureCallback", 0));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(GodotTaskScheduler, Activate, (GodotTaskScheduler_Activate)GODOT_API_CLASS(GodotTaskScheduler)->get_method_thunk("Activate", 0));
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2019-05-18 10:14:21 +08:00
|
|
|
// Start of MarshalUtils methods
|
|
|
|
|
2019-03-06 01:52:19 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, TypeIsGenericArray, (TypeIsGenericArray)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("TypeIsGenericArray", 1));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, TypeIsGenericDictionary, (TypeIsGenericDictionary)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("TypeIsGenericDictionary", 1));
|
2019-05-18 10:14:21 +08:00
|
|
|
|
2019-03-06 04:39:50 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, ArrayGetElementType, (ArrayGetElementType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("ArrayGetElementType", 2));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, DictionaryGetKeyValueTypes, (DictionaryGetKeyValueTypes)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("DictionaryGetKeyValueTypes", 3));
|
2019-05-18 10:14:21 +08:00
|
|
|
|
2019-05-22 01:09:00 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIEnumerableIsAssignableFromType, (GenericIEnumerableIsAssignableFromType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIEnumerableIsAssignableFromType", 1));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryIsAssignableFromType, (GenericIDictionaryIsAssignableFromType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIDictionaryIsAssignableFromType", 1));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIEnumerableIsAssignableFromType_with_info, (GenericIEnumerableIsAssignableFromType_with_info)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIEnumerableIsAssignableFromType", 2));
|
2019-05-21 00:34:35 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryIsAssignableFromType_with_info, (GenericIDictionaryIsAssignableFromType_with_info)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIDictionaryIsAssignableFromType", 3));
|
2019-05-18 10:14:21 +08:00
|
|
|
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, MakeGenericArrayType, (MakeGenericArrayType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("MakeGenericArrayType", 1));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, MakeGenericDictionaryType, (MakeGenericDictionaryType)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("MakeGenericDictionaryType", 2));
|
|
|
|
|
2019-03-06 01:52:19 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, EnumerableToArray, (EnumerableToArray)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("EnumerableToArray", 2));
|
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, IDictionaryToDictionary, (IDictionaryToDictionary)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("IDictionaryToDictionary", 2));
|
2019-05-18 10:14:21 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(MarshalUtils, GenericIDictionaryToDictionary, (GenericIDictionaryToDictionary)GODOT_API_CLASS(MarshalUtils)->get_method_thunk("GenericIDictionaryToDictionary", 2));
|
|
|
|
|
|
|
|
// End of MarshalUtils methods
|
2019-03-06 01:52:19 +08:00
|
|
|
|
2018-01-10 00:19:03 +08:00
|
|
|
#ifdef DEBUG_ENABLED
|
2018-07-26 03:30:11 +08:00
|
|
|
CACHE_METHOD_THUNK_AND_CHECK(DebuggingUtils, GetStackFrameInfo, (DebugUtils_StackFrameInfo)GODOT_API_CLASS(DebuggingUtils)->get_method_thunk("GetStackFrameInfo", 4));
|
2018-01-10 00:19:03 +08:00
|
|
|
#endif
|
|
|
|
|
2018-09-12 08:41:54 +08:00
|
|
|
// TODO Move to CSharpLanguage::init() and do handle disposal
|
2019-07-03 15:44:53 +08:00
|
|
|
MonoObject *task_scheduler = mono_object_new(mono_domain_get(), GODOT_API_CLASS(GodotTaskScheduler)->get_mono_ptr());
|
2019-05-21 06:06:04 +08:00
|
|
|
GDMonoUtils::runtime_object_init(task_scheduler, GODOT_API_CLASS(GodotTaskScheduler));
|
2017-10-03 05:24:00 +08:00
|
|
|
mono_cache.task_scheduler_handle = MonoGCHandle::create_strong(task_scheduler);
|
2018-01-13 02:23:11 +08:00
|
|
|
|
2018-02-22 20:13:51 +08:00
|
|
|
mono_cache.godot_api_cache_updated = true;
|
2017-10-03 05:24:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *unmanaged_get_managed(Object *unmanaged) {
|
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
if (!unmanaged)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
if (unmanaged->get_script_instance()) {
|
|
|
|
CSharpInstance *cs_instance = CAST_CSHARP_INSTANCE(unmanaged->get_script_instance());
|
|
|
|
|
|
|
|
if (cs_instance) {
|
|
|
|
return cs_instance->get_mono_object();
|
2017-10-03 05:24:00 +08:00
|
|
|
}
|
2019-02-03 13:35:22 +08:00
|
|
|
}
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
// If the owner does not have a CSharpInstance...
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
void *data = unmanaged->get_script_instance_binding(CSharpLanguage::get_singleton()->get_language_index());
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2019-02-05 03:39:02 +08:00
|
|
|
ERR_FAIL_NULL_V(data, NULL);
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
CSharpScriptBinding &script_binding = ((Map<Object *, CSharpScriptBinding>::Element *)data)->value();
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
if (!script_binding.inited) {
|
2019-02-05 03:39:02 +08:00
|
|
|
SCOPED_MUTEX_LOCK(CSharpLanguage::get_singleton()->get_language_bind_mutex());
|
|
|
|
|
|
|
|
if (!script_binding.inited) { // Other thread may have set it up
|
|
|
|
// Already had a binding that needs to be setup
|
|
|
|
CSharpLanguage::get_singleton()->setup_csharp_script_binding(script_binding, unmanaged);
|
2019-02-03 13:35:22 +08:00
|
|
|
|
2019-02-05 03:39:02 +08:00
|
|
|
ERR_FAIL_COND_V(!script_binding.inited, NULL);
|
|
|
|
}
|
2019-02-03 13:35:22 +08:00
|
|
|
}
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
Ref<MonoGCHandle> &gchandle = script_binding.gchandle;
|
|
|
|
ERR_FAIL_COND_V(gchandle.is_null(), NULL);
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
MonoObject *target = gchandle->get_target();
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
if (target)
|
|
|
|
return target;
|
|
|
|
|
|
|
|
CSharpLanguage::get_singleton()->release_script_gchandle(gchandle);
|
|
|
|
|
|
|
|
// Create a new one
|
2018-09-12 08:41:54 +08:00
|
|
|
|
|
|
|
#ifdef DEBUG_ENABLED
|
2019-02-03 13:35:22 +08:00
|
|
|
CRASH_COND(script_binding.type_name == StringName());
|
|
|
|
CRASH_COND(script_binding.wrapper_class == NULL);
|
2018-09-12 08:41:54 +08:00
|
|
|
#endif
|
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
MonoObject *mono_object = GDMonoUtils::create_managed_for_godot_object(script_binding.wrapper_class, script_binding.type_name, unmanaged);
|
|
|
|
ERR_FAIL_NULL_V(mono_object, NULL);
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
gchandle->set_handle(MonoGCHandle::new_strong_handle(mono_object), MonoGCHandle::STRONG_HANDLE);
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
// Tie managed to unmanaged
|
|
|
|
Reference *ref = Object::cast_to<Reference>(unmanaged);
|
2018-09-12 08:41:54 +08:00
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
if (ref) {
|
|
|
|
// Unsafe refcount increment. The managed instance also counts as a reference.
|
|
|
|
// This way if the unmanaged world has no references to our owner
|
|
|
|
// but the managed instance is alive, the refcount will be 1 instead of 0.
|
|
|
|
// See: godot_icall_Reference_Dtor(MonoObject *p_obj, Object *p_ptr)
|
|
|
|
ref->reference();
|
2017-10-03 05:24:00 +08:00
|
|
|
}
|
|
|
|
|
2019-02-03 13:35:22 +08:00
|
|
|
return mono_object;
|
2017-10-03 05:24:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void set_main_thread(MonoThread *p_thread) {
|
|
|
|
mono_thread_set_main(p_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
void attach_current_thread() {
|
|
|
|
ERR_FAIL_COND(!GDMono::get_singleton()->is_runtime_initialized());
|
2019-07-03 15:44:53 +08:00
|
|
|
MonoThread *mono_thread = mono_thread_attach(mono_domain_get());
|
2017-10-03 05:24:00 +08:00
|
|
|
ERR_FAIL_NULL(mono_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
void detach_current_thread() {
|
|
|
|
ERR_FAIL_COND(!GDMono::get_singleton()->is_runtime_initialized());
|
|
|
|
MonoThread *mono_thread = mono_thread_current();
|
|
|
|
ERR_FAIL_NULL(mono_thread);
|
|
|
|
mono_thread_detach(mono_thread);
|
|
|
|
}
|
|
|
|
|
|
|
|
MonoThread *get_current_thread() {
|
|
|
|
return mono_thread_current();
|
|
|
|
}
|
|
|
|
|
2019-05-21 06:06:04 +08:00
|
|
|
void runtime_object_init(MonoObject *p_this_obj, GDMonoClass *p_class, MonoException **r_exc) {
|
|
|
|
GDMonoMethod *ctor = p_class->get_method(".ctor", 0);
|
|
|
|
ERR_FAIL_NULL(ctor);
|
|
|
|
ctor->invoke_raw(p_this_obj, NULL, r_exc);
|
2018-07-19 05:07:57 +08:00
|
|
|
}
|
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
GDMonoClass *get_object_class(MonoObject *p_object) {
|
|
|
|
return GDMono::get_singleton()->get_class(mono_object_get_class(p_object));
|
|
|
|
}
|
|
|
|
|
|
|
|
GDMonoClass *type_get_proxy_class(const StringName &p_type) {
|
|
|
|
String class_name = p_type;
|
|
|
|
|
|
|
|
if (class_name[0] == '_')
|
|
|
|
class_name = class_name.substr(1, class_name.length());
|
|
|
|
|
2018-02-22 20:13:51 +08:00
|
|
|
GDMonoClass *klass = GDMono::get_singleton()->get_core_api_assembly()->get_class(BINDINGS_NAMESPACE, class_name);
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2019-02-20 05:36:27 +08:00
|
|
|
if (klass && klass->is_static()) {
|
|
|
|
// A static class means this is a Godot singleton class. If an instance is needed we use Godot.Object.
|
|
|
|
return mono_cache.class_GodotObject;
|
|
|
|
}
|
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (!klass) {
|
|
|
|
return GDMono::get_singleton()->get_editor_api_assembly()->get_class(BINDINGS_NAMESPACE, class_name);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return klass;
|
|
|
|
}
|
|
|
|
|
|
|
|
GDMonoClass *get_class_native_base(GDMonoClass *p_class) {
|
|
|
|
GDMonoClass *klass = p_class;
|
|
|
|
|
|
|
|
do {
|
|
|
|
const GDMonoAssembly *assembly = klass->get_assembly();
|
2018-02-22 20:13:51 +08:00
|
|
|
if (assembly == GDMono::get_singleton()->get_core_api_assembly())
|
2017-10-03 05:24:00 +08:00
|
|
|
return klass;
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (assembly == GDMono::get_singleton()->get_editor_api_assembly())
|
|
|
|
return klass;
|
|
|
|
#endif
|
|
|
|
} while ((klass = klass->get_parent_class()) != NULL);
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *create_managed_for_godot_object(GDMonoClass *p_class, const StringName &p_native, Object *p_object) {
|
2019-08-09 09:39:45 +08:00
|
|
|
bool parent_is_object_class = ClassDB::is_parent_class(p_object->get_class_name(), p_native);
|
|
|
|
ERR_FAIL_COND_V_MSG(!parent_is_object_class, NULL,
|
|
|
|
"Type inherits from native type '" + p_native + "', so it can't be instanced in object of type: '" + p_object->get_class() + "'.");
|
2017-10-03 05:24:00 +08:00
|
|
|
|
2019-07-03 15:44:53 +08:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr());
|
2017-10-03 05:24:00 +08:00
|
|
|
ERR_FAIL_NULL_V(mono_object, NULL);
|
|
|
|
|
|
|
|
CACHED_FIELD(GodotObject, ptr)->set_value_raw(mono_object, p_object);
|
|
|
|
|
|
|
|
// Construct
|
2019-05-21 06:06:04 +08:00
|
|
|
GDMonoUtils::runtime_object_init(mono_object, p_class);
|
2017-10-03 05:24:00 +08:00
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *create_managed_from(const NodePath &p_from) {
|
2019-07-03 15:44:53 +08:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), CACHED_CLASS_RAW(NodePath));
|
2017-10-03 05:24:00 +08:00
|
|
|
ERR_FAIL_NULL_V(mono_object, NULL);
|
|
|
|
|
|
|
|
// Construct
|
2019-05-21 06:06:04 +08:00
|
|
|
GDMonoUtils::runtime_object_init(mono_object, CACHED_CLASS(NodePath));
|
2017-10-03 05:24:00 +08:00
|
|
|
|
|
|
|
CACHED_FIELD(NodePath, ptr)->set_value_raw(mono_object, memnew(NodePath(p_from)));
|
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *create_managed_from(const RID &p_from) {
|
2019-07-03 15:44:53 +08:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), CACHED_CLASS_RAW(RID));
|
2017-10-03 05:24:00 +08:00
|
|
|
ERR_FAIL_NULL_V(mono_object, NULL);
|
|
|
|
|
|
|
|
// Construct
|
2019-05-21 06:06:04 +08:00
|
|
|
GDMonoUtils::runtime_object_init(mono_object, CACHED_CLASS(RID));
|
2017-10-03 05:24:00 +08:00
|
|
|
|
|
|
|
CACHED_FIELD(RID, ptr)->set_value_raw(mono_object, memnew(RID(p_from)));
|
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
2018-07-19 05:07:57 +08:00
|
|
|
MonoObject *create_managed_from(const Array &p_from, GDMonoClass *p_class) {
|
2019-07-03 15:44:53 +08:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr());
|
2018-07-19 05:07:57 +08:00
|
|
|
ERR_FAIL_NULL_V(mono_object, NULL);
|
|
|
|
|
|
|
|
// Search constructor that takes a pointer as parameter
|
|
|
|
MonoMethod *m;
|
|
|
|
void *iter = NULL;
|
|
|
|
while ((m = mono_class_get_methods(p_class->get_mono_ptr(), &iter))) {
|
|
|
|
if (strcmp(mono_method_get_name(m), ".ctor") == 0) {
|
|
|
|
MonoMethodSignature *sig = mono_method_signature(m);
|
|
|
|
void *front = NULL;
|
|
|
|
if (mono_signature_get_param_count(sig) == 1 &&
|
|
|
|
mono_class_from_mono_type(mono_signature_get_params(sig, &front)) == CACHED_CLASS(IntPtr)->get_mono_ptr()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CRASH_COND(m == NULL);
|
|
|
|
|
|
|
|
Array *new_array = memnew(Array(p_from));
|
|
|
|
void *args[1] = { &new_array };
|
|
|
|
|
|
|
|
MonoException *exc = NULL;
|
2018-08-01 01:40:38 +08:00
|
|
|
GDMonoUtils::runtime_invoke(m, mono_object, args, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2018-07-19 05:07:57 +08:00
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
|
|
|
MonoObject *create_managed_from(const Dictionary &p_from, GDMonoClass *p_class) {
|
2019-07-03 15:44:53 +08:00
|
|
|
MonoObject *mono_object = mono_object_new(mono_domain_get(), p_class->get_mono_ptr());
|
2018-07-19 05:07:57 +08:00
|
|
|
ERR_FAIL_NULL_V(mono_object, NULL);
|
|
|
|
|
|
|
|
// Search constructor that takes a pointer as parameter
|
|
|
|
MonoMethod *m;
|
|
|
|
void *iter = NULL;
|
|
|
|
while ((m = mono_class_get_methods(p_class->get_mono_ptr(), &iter))) {
|
|
|
|
if (strcmp(mono_method_get_name(m), ".ctor") == 0) {
|
|
|
|
MonoMethodSignature *sig = mono_method_signature(m);
|
|
|
|
void *front = NULL;
|
|
|
|
if (mono_signature_get_param_count(sig) == 1 &&
|
|
|
|
mono_class_from_mono_type(mono_signature_get_params(sig, &front)) == CACHED_CLASS(IntPtr)->get_mono_ptr()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
CRASH_COND(m == NULL);
|
|
|
|
|
|
|
|
Dictionary *new_dict = memnew(Dictionary(p_from));
|
|
|
|
void *args[1] = { &new_dict };
|
|
|
|
|
|
|
|
MonoException *exc = NULL;
|
2018-08-01 01:40:38 +08:00
|
|
|
GDMonoUtils::runtime_invoke(m, mono_object, args, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2018-07-19 05:07:57 +08:00
|
|
|
|
|
|
|
return mono_object;
|
|
|
|
}
|
|
|
|
|
2017-10-03 05:24:00 +08:00
|
|
|
MonoDomain *create_domain(const String &p_friendly_name) {
|
|
|
|
MonoDomain *domain = mono_domain_create_appdomain((char *)p_friendly_name.utf8().get_data(), NULL);
|
|
|
|
|
|
|
|
if (domain) {
|
|
|
|
// Workaround to avoid this exception:
|
|
|
|
// System.Configuration.ConfigurationErrorsException: Error Initializing the configuration system.
|
|
|
|
// ---> System.ArgumentException: The 'ExeConfigFilename' argument cannot be null.
|
|
|
|
mono_domain_set_config(domain, ".", "");
|
|
|
|
}
|
|
|
|
|
|
|
|
return domain;
|
|
|
|
}
|
|
|
|
|
2018-07-19 05:07:57 +08:00
|
|
|
String get_exception_name_and_message(MonoException *p_exc) {
|
2017-10-03 05:24:00 +08:00
|
|
|
String res;
|
|
|
|
|
2018-07-19 05:07:57 +08:00
|
|
|
MonoClass *klass = mono_object_get_class((MonoObject *)p_exc);
|
2017-10-03 05:24:00 +08:00
|
|
|
MonoType *type = mono_class_get_type(klass);
|
|
|
|
|
|
|
|
char *full_name = mono_type_full_name(type);
|
|
|
|
res += full_name;
|
|
|
|
mono_free(full_name);
|
|
|
|
|
|
|
|
res += ": ";
|
|
|
|
|
|
|
|
MonoProperty *prop = mono_class_get_property_from_name(klass, "Message");
|
2018-08-01 01:40:38 +08:00
|
|
|
MonoString *msg = (MonoString *)property_get_value(prop, (MonoObject *)p_exc, NULL, NULL);
|
2017-10-03 05:24:00 +08:00
|
|
|
res += GDMonoMarshal::mono_string_to_godot(msg);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
2018-01-05 04:05:46 +08:00
|
|
|
|
2018-07-19 05:07:57 +08:00
|
|
|
void set_exception_message(MonoException *p_exc, String message) {
|
|
|
|
MonoClass *klass = mono_object_get_class((MonoObject *)p_exc);
|
|
|
|
MonoProperty *prop = mono_class_get_property_from_name(klass, "Message");
|
|
|
|
MonoString *msg = GDMonoMarshal::mono_string_from_godot(message);
|
|
|
|
void *params[1] = { msg };
|
2018-08-01 01:40:38 +08:00
|
|
|
property_set_value(prop, (MonoObject *)p_exc, params, NULL);
|
2018-07-19 05:07:57 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
void debug_print_unhandled_exception(MonoException *p_exc) {
|
|
|
|
print_unhandled_exception(p_exc);
|
|
|
|
debug_send_unhandled_exception_error(p_exc);
|
2018-01-10 00:19:03 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
void debug_send_unhandled_exception_error(MonoException *p_exc) {
|
2018-01-10 00:19:03 +08:00
|
|
|
#ifdef DEBUG_ENABLED
|
2019-07-25 05:13:24 +08:00
|
|
|
if (!ScriptDebugger::get_singleton()) {
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
if (Engine::get_singleton()->is_editor_hint()) {
|
|
|
|
ERR_PRINTS(GDMonoUtils::get_exception_name_and_message(p_exc));
|
|
|
|
}
|
|
|
|
#endif
|
2018-01-13 02:23:11 +08:00
|
|
|
return;
|
2019-07-25 05:13:24 +08:00
|
|
|
}
|
2018-01-13 02:23:11 +08:00
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
_TLS_RECURSION_GUARD_;
|
|
|
|
|
2018-02-24 23:36:48 +08:00
|
|
|
ScriptLanguage::StackInfo separator;
|
2018-06-27 03:03:42 +08:00
|
|
|
separator.file = String();
|
2018-02-27 17:36:58 +08:00
|
|
|
separator.func = "--- " + RTR("End of inner exception stack trace") + " ---";
|
2018-02-24 23:36:48 +08:00
|
|
|
separator.line = 0;
|
2018-01-10 00:19:03 +08:00
|
|
|
|
2018-02-24 23:36:48 +08:00
|
|
|
Vector<ScriptLanguage::StackInfo> si;
|
2018-06-27 03:03:42 +08:00
|
|
|
String exc_msg;
|
2018-02-24 23:36:48 +08:00
|
|
|
|
|
|
|
while (p_exc != NULL) {
|
|
|
|
GDMonoClass *st_klass = CACHED_CLASS(System_Diagnostics_StackTrace);
|
|
|
|
MonoObject *stack_trace = mono_object_new(mono_domain_get(), st_klass->get_mono_ptr());
|
|
|
|
|
|
|
|
MonoBoolean need_file_info = true;
|
|
|
|
void *ctor_args[2] = { p_exc, &need_file_info };
|
2018-01-10 00:19:03 +08:00
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
MonoException *unexpected_exc = NULL;
|
2018-02-24 23:36:48 +08:00
|
|
|
CACHED_METHOD(System_Diagnostics_StackTrace, ctor_Exception_bool)->invoke_raw(stack_trace, ctor_args, &unexpected_exc);
|
2018-01-10 00:19:03 +08:00
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
if (unexpected_exc) {
|
|
|
|
GDMonoInternals::unhandled_exception(unexpected_exc);
|
2019-07-25 05:13:24 +08:00
|
|
|
return;
|
2018-01-10 00:19:03 +08:00
|
|
|
}
|
|
|
|
|
2018-02-24 23:36:48 +08:00
|
|
|
Vector<ScriptLanguage::StackInfo> _si;
|
2018-06-27 03:03:42 +08:00
|
|
|
if (stack_trace != NULL) {
|
2018-02-24 23:36:48 +08:00
|
|
|
_si = CSharpLanguage::get_singleton()->stack_trace_get_info(stack_trace);
|
|
|
|
for (int i = _si.size() - 1; i >= 0; i--)
|
|
|
|
si.insert(0, _si[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
exc_msg += (exc_msg.length() > 0 ? " ---> " : "") + GDMonoUtils::get_exception_name_and_message(p_exc);
|
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
GDMonoClass *exc_class = GDMono::get_singleton()->get_class(mono_get_exception_class());
|
|
|
|
GDMonoProperty *inner_exc_prop = exc_class->get_property("InnerException");
|
|
|
|
CRASH_COND(inner_exc_prop == NULL);
|
|
|
|
|
|
|
|
MonoObject *inner_exc = inner_exc_prop->get_value((MonoObject *)p_exc);
|
|
|
|
if (inner_exc != NULL)
|
2018-02-24 23:36:48 +08:00
|
|
|
si.insert(0, separator);
|
2018-06-27 03:03:42 +08:00
|
|
|
|
|
|
|
p_exc = (MonoException *)inner_exc;
|
2018-02-24 23:36:48 +08:00
|
|
|
}
|
2018-01-10 00:19:03 +08:00
|
|
|
|
|
|
|
String file = si.size() ? si[0].file : __FILE__;
|
|
|
|
String func = si.size() ? si[0].func : FUNCTION_STR;
|
|
|
|
int line = si.size() ? si[0].line : __LINE__;
|
|
|
|
String error_msg = "Unhandled exception";
|
|
|
|
|
|
|
|
ScriptDebugger::get_singleton()->send_error(func, file, line, error_msg, exc_msg, ERR_HANDLER_ERROR, si);
|
|
|
|
#endif
|
2018-01-05 04:05:46 +08:00
|
|
|
}
|
|
|
|
|
2018-06-27 03:03:42 +08:00
|
|
|
void debug_unhandled_exception(MonoException *p_exc) {
|
|
|
|
GDMonoInternals::unhandled_exception(p_exc); // prints the exception as well
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_unhandled_exception(MonoException *p_exc) {
|
|
|
|
mono_print_unhandled_exception((MonoObject *)p_exc);
|
|
|
|
}
|
|
|
|
|
|
|
|
void set_pending_exception(MonoException *p_exc) {
|
2019-07-03 15:44:53 +08:00
|
|
|
#ifdef NO_PENDING_EXCEPTIONS
|
|
|
|
debug_unhandled_exception(p_exc);
|
|
|
|
#else
|
2018-06-27 03:03:42 +08:00
|
|
|
if (get_runtime_invoke_count() == 0) {
|
|
|
|
debug_unhandled_exception(p_exc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mono_runtime_set_pending_exception(p_exc, false)) {
|
|
|
|
ERR_PRINTS("Exception thrown from managed code, but it could not be set as pending:");
|
|
|
|
GDMonoUtils::debug_print_unhandled_exception(p_exc);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
_THREAD_LOCAL_(int)
|
|
|
|
current_invoke_count = 0;
|
|
|
|
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoObject *runtime_invoke(MonoMethod *p_method, void *p_obj, void **p_params, MonoException **r_exc) {
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoObject *ret = mono_runtime_invoke(p_method, p_obj, p_params, (MonoObject **)r_exc);
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoObject *runtime_invoke_array(MonoMethod *p_method, void *p_obj, MonoArray *p_params, MonoException **r_exc) {
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoObject *ret = mono_runtime_invoke_array(p_method, p_obj, p_params, (MonoObject **)r_exc);
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoString *object_to_string(MonoObject *p_obj, MonoException **r_exc) {
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoString *ret = mono_object_to_string(p_obj, (MonoObject **)r_exc);
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:05:19 +08:00
|
|
|
void property_set_value(MonoProperty *p_prop, void *p_obj, void **p_params, MonoException **r_exc) {
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 08:05:19 +08:00
|
|
|
mono_property_set_value(p_prop, p_obj, p_params, (MonoObject **)r_exc);
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
}
|
|
|
|
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoObject *property_get_value(MonoProperty *p_prop, void *p_obj, void **p_params, MonoException **r_exc) {
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_BEGIN_RUNTIME_INVOKE;
|
2018-11-08 08:05:19 +08:00
|
|
|
MonoObject *ret = mono_property_get_value(p_prop, p_obj, p_params, (MonoObject **)r_exc);
|
2018-08-01 01:40:38 +08:00
|
|
|
GD_MONO_END_RUNTIME_INVOKE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2018-09-13 00:54:20 +08:00
|
|
|
uint64_t unbox_enum_value(MonoObject *p_boxed, MonoType *p_enum_basetype, bool &r_error) {
|
|
|
|
r_error = false;
|
|
|
|
switch (mono_type_get_type(p_enum_basetype)) {
|
|
|
|
case MONO_TYPE_BOOLEAN:
|
|
|
|
return (bool)GDMonoMarshal::unbox<MonoBoolean>(p_boxed) ? 1 : 0;
|
|
|
|
case MONO_TYPE_CHAR:
|
|
|
|
return GDMonoMarshal::unbox<uint16_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U1:
|
|
|
|
return GDMonoMarshal::unbox<uint8_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U2:
|
|
|
|
return GDMonoMarshal::unbox<uint16_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U4:
|
|
|
|
return GDMonoMarshal::unbox<uint32_t>(p_boxed);
|
|
|
|
case MONO_TYPE_U8:
|
|
|
|
return GDMonoMarshal::unbox<uint64_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I1:
|
|
|
|
return GDMonoMarshal::unbox<int8_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I2:
|
|
|
|
return GDMonoMarshal::unbox<int16_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I4:
|
|
|
|
return GDMonoMarshal::unbox<int32_t>(p_boxed);
|
|
|
|
case MONO_TYPE_I8:
|
|
|
|
return GDMonoMarshal::unbox<int64_t>(p_boxed);
|
|
|
|
default:
|
|
|
|
r_error = true;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-01 03:43:06 +08:00
|
|
|
void dispose(MonoObject *p_mono_object, MonoException **r_exc) {
|
2019-03-06 01:52:19 +08:00
|
|
|
invoke_method_thunk(CACHED_METHOD_THUNK(GodotObject, Dispose), p_mono_object, r_exc);
|
2018-12-01 03:43:06 +08:00
|
|
|
}
|
|
|
|
|
2019-05-18 10:14:21 +08:00
|
|
|
namespace Marshal {
|
|
|
|
|
2019-07-03 15:44:53 +08:00
|
|
|
#ifdef MONO_GLUE_ENABLED
|
|
|
|
#ifdef TOOLS_ENABLED
|
|
|
|
#define NO_GLUE_RET(m_ret) \
|
|
|
|
{ \
|
|
|
|
if (!mono_cache.godot_api_cache_updated) return m_ret; \
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
#define NO_GLUE_RET(m_ret) \
|
|
|
|
{}
|
|
|
|
#endif
|
|
|
|
#else
|
|
|
|
#define NO_GLUE_RET(m_ret) \
|
|
|
|
{ return m_ret; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
bool type_is_generic_array(MonoReflectionType *p_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2019-05-18 10:14:21 +08:00
|
|
|
TypeIsGenericArray thunk = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericArray);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 10:14:21 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 15:44:53 +08:00
|
|
|
bool type_is_generic_dictionary(MonoReflectionType *p_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2019-05-18 10:14:21 +08:00
|
|
|
TypeIsGenericDictionary thunk = CACHED_METHOD_THUNK(MarshalUtils, TypeIsGenericDictionary);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 10:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void array_get_element_type(MonoReflectionType *p_array_reftype, MonoReflectionType **r_elem_reftype) {
|
|
|
|
ArrayGetElementType thunk = CACHED_METHOD_THUNK(MarshalUtils, ArrayGetElementType);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
invoke_method_thunk(thunk, p_array_reftype, r_elem_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 10:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void dictionary_get_key_value_types(MonoReflectionType *p_dict_reftype, MonoReflectionType **r_key_reftype, MonoReflectionType **r_value_reftype) {
|
|
|
|
DictionaryGetKeyValueTypes thunk = CACHED_METHOD_THUNK(MarshalUtils, DictionaryGetKeyValueTypes);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
invoke_method_thunk(thunk, p_dict_reftype, r_key_reftype, r_value_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 10:14:21 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 15:44:53 +08:00
|
|
|
bool generic_ienumerable_is_assignable_from(MonoReflectionType *p_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2019-05-18 10:14:21 +08:00
|
|
|
GenericIEnumerableIsAssignableFromType thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIEnumerableIsAssignableFromType);
|
|
|
|
MonoException *exc = NULL;
|
2019-05-22 01:09:00 +08:00
|
|
|
MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-22 01:09:00 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 15:44:53 +08:00
|
|
|
bool generic_idictionary_is_assignable_from(MonoReflectionType *p_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2019-05-22 01:09:00 +08:00
|
|
|
GenericIDictionaryIsAssignableFromType thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryIsAssignableFromType);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
MonoBoolean res = invoke_method_thunk(thunk, p_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-22 01:09:00 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 15:44:53 +08:00
|
|
|
bool generic_ienumerable_is_assignable_from(MonoReflectionType *p_reftype, MonoReflectionType **r_elem_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2019-05-22 01:09:00 +08:00
|
|
|
GenericIEnumerableIsAssignableFromType_with_info thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIEnumerableIsAssignableFromType_with_info);
|
|
|
|
MonoException *exc = NULL;
|
2019-05-18 10:14:21 +08:00
|
|
|
MonoBoolean res = invoke_method_thunk(thunk, p_reftype, r_elem_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 10:14:21 +08:00
|
|
|
}
|
|
|
|
|
2019-07-03 15:44:53 +08:00
|
|
|
bool generic_idictionary_is_assignable_from(MonoReflectionType *p_reftype, MonoReflectionType **r_key_reftype, MonoReflectionType **r_value_reftype) {
|
|
|
|
NO_GLUE_RET(false);
|
2019-05-22 01:09:00 +08:00
|
|
|
GenericIDictionaryIsAssignableFromType_with_info thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryIsAssignableFromType_with_info);
|
2019-05-18 10:14:21 +08:00
|
|
|
MonoException *exc = NULL;
|
|
|
|
MonoBoolean res = invoke_method_thunk(thunk, p_reftype, r_key_reftype, r_value_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
|
|
|
return (bool)res;
|
2019-05-18 10:14:21 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Array enumerable_to_array(MonoObject *p_enumerable) {
|
2019-07-03 15:44:53 +08:00
|
|
|
NO_GLUE_RET(Array());
|
2019-05-18 10:14:21 +08:00
|
|
|
Array result;
|
|
|
|
EnumerableToArray thunk = CACHED_METHOD_THUNK(MarshalUtils, EnumerableToArray);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
invoke_method_thunk(thunk, p_enumerable, &result, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 10:14:21 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary idictionary_to_dictionary(MonoObject *p_idictionary) {
|
2019-07-03 15:44:53 +08:00
|
|
|
NO_GLUE_RET(Dictionary());
|
2019-05-18 10:14:21 +08:00
|
|
|
Dictionary result;
|
|
|
|
IDictionaryToDictionary thunk = CACHED_METHOD_THUNK(MarshalUtils, IDictionaryToDictionary);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
invoke_method_thunk(thunk, p_idictionary, &result, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 10:14:21 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
Dictionary generic_idictionary_to_dictionary(MonoObject *p_generic_idictionary) {
|
2019-07-03 15:44:53 +08:00
|
|
|
NO_GLUE_RET(Dictionary());
|
2019-05-18 10:14:21 +08:00
|
|
|
Dictionary result;
|
|
|
|
GenericIDictionaryToDictionary thunk = CACHED_METHOD_THUNK(MarshalUtils, GenericIDictionaryToDictionary);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
invoke_method_thunk(thunk, p_generic_idictionary, &result, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 10:14:21 +08:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
GDMonoClass *make_generic_array_type(MonoReflectionType *p_elem_reftype) {
|
2019-07-03 15:44:53 +08:00
|
|
|
NO_GLUE_RET(NULL);
|
2019-05-18 10:14:21 +08:00
|
|
|
MakeGenericArrayType thunk = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericArrayType);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
MonoReflectionType *reftype = invoke_method_thunk(thunk, p_elem_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 10:14:21 +08:00
|
|
|
return GDMono::get_singleton()->get_class(mono_class_from_mono_type(mono_reflection_type_get_type(reftype)));
|
|
|
|
}
|
|
|
|
|
|
|
|
GDMonoClass *make_generic_dictionary_type(MonoReflectionType *p_key_reftype, MonoReflectionType *p_value_reftype) {
|
2019-07-03 15:44:53 +08:00
|
|
|
NO_GLUE_RET(NULL);
|
2019-05-18 10:14:21 +08:00
|
|
|
MakeGenericDictionaryType thunk = CACHED_METHOD_THUNK(MarshalUtils, MakeGenericDictionaryType);
|
|
|
|
MonoException *exc = NULL;
|
|
|
|
MonoReflectionType *reftype = invoke_method_thunk(thunk, p_key_reftype, p_value_reftype, &exc);
|
2019-07-03 15:44:53 +08:00
|
|
|
UNHANDLED_EXCEPTION(exc);
|
2019-05-18 10:14:21 +08:00
|
|
|
return GDMono::get_singleton()->get_class(mono_class_from_mono_type(mono_reflection_type_get_type(reftype)));
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Marshal
|
|
|
|
|
2017-11-17 10:09:00 +08:00
|
|
|
} // namespace GDMonoUtils
|