summaryrefslogtreecommitdiff
path: root/modules/mono
diff options
context:
space:
mode:
Diffstat (limited to 'modules/mono')
-rw-r--r--modules/mono/csharp_script.cpp363
-rw-r--r--modules/mono/csharp_script.h13
-rw-r--r--modules/mono/doc_classes/@C#.xml2
-rw-r--r--modules/mono/doc_classes/CSharpScript.xml2
-rw-r--r--modules/mono/doc_classes/GodotSharp.xml2
-rw-r--r--modules/mono/editor/bindings_generator.cpp170
-rw-r--r--modules/mono/editor/bindings_generator.h5
-rw-r--r--modules/mono/editor/csharp_project.cpp1
-rw-r--r--modules/mono/editor/csharp_project.h1
-rw-r--r--modules/mono/editor/godotsharp_builds.cpp3
-rw-r--r--modules/mono/editor/godotsharp_builds.h1
-rw-r--r--modules/mono/editor/godotsharp_editor.cpp94
-rw-r--r--modules/mono/editor/godotsharp_editor.h9
-rw-r--r--modules/mono/editor/mono_bottom_panel.cpp1
-rw-r--r--modules/mono/editor/mono_bottom_panel.h1
-rw-r--r--modules/mono/editor/mono_build_info.h1
-rw-r--r--modules/mono/editor/monodevelop_instance.cpp5
-rw-r--r--modules/mono/editor/monodevelop_instance.h1
-rw-r--r--modules/mono/editor/net_solution.cpp1
-rw-r--r--modules/mono/editor/net_solution.h1
-rw-r--r--modules/mono/glue/builtin_types_glue.h59
-rw-r--r--modules/mono/glue/cs_files/Color.cs26
-rw-r--r--modules/mono/glue/cs_files/DebuggingUtils.cs83
-rw-r--r--modules/mono/glue/cs_files/Plane.cs2
-rw-r--r--modules/mono/glue/glue_header.h19
-rw-r--r--modules/mono/godotsharp_defs.h1
-rw-r--r--modules/mono/godotsharp_dirs.cpp1
-rw-r--r--modules/mono/godotsharp_dirs.h1
-rw-r--r--modules/mono/mono_gc_handle.cpp1
-rw-r--r--modules/mono/mono_gc_handle.h1
-rw-r--r--modules/mono/mono_gd/gd_mono.cpp18
-rw-r--r--modules/mono/mono_gd/gd_mono.h9
-rw-r--r--modules/mono/mono_gd/gd_mono_assembly.cpp3
-rw-r--r--modules/mono/mono_gd/gd_mono_assembly.h1
-rw-r--r--modules/mono/mono_gd/gd_mono_class.cpp82
-rw-r--r--modules/mono/mono_gd/gd_mono_class.h17
-rw-r--r--modules/mono/mono_gd/gd_mono_class_member.h67
-rw-r--r--modules/mono/mono_gd/gd_mono_field.cpp35
-rw-r--r--modules/mono/mono_gd/gd_mono_field.h36
-rw-r--r--modules/mono/mono_gd/gd_mono_header.h5
-rw-r--r--modules/mono/mono_gd/gd_mono_internals.cpp3
-rw-r--r--modules/mono/mono_gd/gd_mono_internals.h3
-rw-r--r--modules/mono/mono_gd/gd_mono_log.cpp1
-rw-r--r--modules/mono/mono_gd/gd_mono_log.h1
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.cpp29
-rw-r--r--modules/mono/mono_gd/gd_mono_marshal.h2
-rw-r--r--modules/mono/mono_gd/gd_mono_method.cpp46
-rw-r--r--modules/mono/mono_gd/gd_mono_method.h22
-rw-r--r--modules/mono/mono_gd/gd_mono_property.cpp199
-rw-r--r--modules/mono/mono_gd/gd_mono_property.h77
-rw-r--r--modules/mono/mono_gd/gd_mono_utils.cpp104
-rw-r--r--modules/mono/mono_gd/gd_mono_utils.h37
-rw-r--r--modules/mono/register_types.cpp1
-rw-r--r--modules/mono/register_types.h1
-rw-r--r--modules/mono/signal_awaiter_utils.cpp3
-rw-r--r--modules/mono/signal_awaiter_utils.h1
-rw-r--r--modules/mono/utils/mono_reg_utils.cpp1
-rw-r--r--modules/mono/utils/mono_reg_utils.h1
-rw-r--r--modules/mono/utils/path_utils.cpp1
-rw-r--r--modules/mono/utils/path_utils.h1
-rw-r--r--modules/mono/utils/string_utils.cpp1
-rw-r--r--modules/mono/utils/string_utils.h1
62 files changed, 1362 insertions, 318 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp
index f95a3dab2d..3119869569 100644
--- a/modules/mono/csharp_script.cpp
+++ b/modules/mono/csharp_script.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "csharp_script.h"
#include <mono/metadata/threads.h>
@@ -175,7 +176,7 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const {
"fixed",
"float",
"for",
- "forech",
+ "foreach",
"goto",
"if",
"implicit",
@@ -221,14 +222,17 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const {
"ushort",
"using",
"virtual",
- "volatile",
"void",
+ "volatile",
"while",
// Contextual keywords. Not reserved words, but I guess we should include
// them because this seems to be used only for syntax highlighting.
"add",
+ "alias",
"ascending",
+ "async",
+ "await",
"by",
"descending",
"dynamic",
@@ -237,10 +241,10 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const {
"get",
"global",
"group",
- "in",
"into",
"join",
"let",
+ "nameof",
"on",
"orderby",
"partial",
@@ -249,6 +253,7 @@ void CSharpLanguage::get_reserved_words(List<String> *p_words) const {
"set",
"value",
"var",
+ "when",
"where",
"yield",
0
@@ -444,6 +449,82 @@ String CSharpLanguage::_get_indentation() const {
return "\t";
}
+Vector<ScriptLanguage::StackInfo> CSharpLanguage::debug_get_current_stack_info() {
+
+#ifdef DEBUG_ENABLED
+ // Printing an error here will result in endless recursion, so we must be careful
+
+ if (!gdmono->is_runtime_initialized() || !GDMono::get_singleton()->get_api_assembly() || !GDMonoUtils::mono_cache.corlib_cache_updated)
+ return Vector<StackInfo>();
+
+ MonoObject *stack_trace = mono_object_new(mono_domain_get(), CACHED_CLASS(System_Diagnostics_StackTrace)->get_mono_ptr());
+
+ MonoBoolean need_file_info = true;
+ void *ctor_args[1] = { &need_file_info };
+
+ CACHED_METHOD(System_Diagnostics_StackTrace, ctor_bool)->invoke_raw(stack_trace, ctor_args);
+
+ Vector<StackInfo> si;
+ si = stack_trace_get_info(stack_trace);
+
+ return si;
+#else
+ return Vector<StackInfo>();
+#endif
+}
+
+#ifdef DEBUG_ENABLED
+Vector<ScriptLanguage::StackInfo> CSharpLanguage::stack_trace_get_info(MonoObject *p_stack_trace) {
+
+ // Printing an error here could result in endless recursion, so we must be careful
+
+ MonoObject *exc = NULL;
+
+ GDMonoUtils::StackTrace_GetFrames st_get_frames = CACHED_METHOD_THUNK(System_Diagnostics_StackTrace, GetFrames);
+ MonoArray *frames = st_get_frames(p_stack_trace, &exc);
+
+ if (exc) {
+ GDMonoUtils::print_unhandled_exception(exc, true /* fail silently to avoid endless recursion */);
+ return Vector<StackInfo>();
+ }
+
+ int frame_count = mono_array_length(frames);
+
+ if (frame_count <= 0)
+ return Vector<StackInfo>();
+
+ GDMonoUtils::DebugUtils_StackFrameInfo get_sf_info = CACHED_METHOD_THUNK(DebuggingUtils, GetStackFrameInfo);
+
+ Vector<StackInfo> si;
+ si.resize(frame_count);
+
+ for (int i = 0; i < frame_count; i++) {
+ StackInfo &sif = si[i];
+ MonoObject *frame = mono_array_get(frames, MonoObject *, i);
+
+ MonoString *file_name;
+ int file_line_num;
+ MonoString *method_decl;
+ get_sf_info(frame, &file_name, &file_line_num, &method_decl, &exc);
+
+ if (exc) {
+ GDMonoUtils::print_unhandled_exception(exc, true /* fail silently to avoid endless recursion */);
+ return Vector<StackInfo>();
+ }
+
+ // TODO
+ // what if the StackFrame method is null (method_decl is empty). should we skip this frame?
+ // can reproduce with a MissingMethodException on internal calls
+
+ sif.file = GDMonoMarshal::mono_string_to_godot(file_name);
+ sif.line = file_line_num;
+ sif.func = GDMonoMarshal::mono_string_to_godot(method_decl);
+ }
+
+ return si;
+}
+#endif
+
void CSharpLanguage::frame() {
const Ref<MonoGCHandle> &task_scheduler_handle = GDMonoUtils::mono_cache.task_scheduler_handle;
@@ -913,19 +994,23 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
ERR_FAIL_COND_V(!script.is_valid(), false);
+ MonoObject *mono_object = get_mono_object();
+ ERR_FAIL_NULL_V(mono_object, false);
+
GDMonoClass *top = script->script_class;
while (top && top != script->native) {
GDMonoField *field = script->script_class->get_field(p_name);
if (field) {
- MonoObject *mono_object = get_mono_object();
-
- ERR_EXPLAIN("Reference has been garbage collected?");
- ERR_FAIL_NULL_V(mono_object, false);
+ field->set_value_from_variant(mono_object, p_value);
+ return true;
+ }
- field->set_value(mono_object, p_value);
+ GDMonoProperty *property = script->script_class->get_property(p_name);
+ if (property) {
+ property->set_value(mono_object, GDMonoMarshal::variant_to_mono_object(p_value));
return true;
}
@@ -934,16 +1019,15 @@ bool CSharpInstance::set(const StringName &p_name, const Variant &p_value) {
// Call _set
- Variant name = p_name;
- const Variant *args[2] = { &name, &p_value };
-
- MonoObject *mono_object = get_mono_object();
top = script->script_class;
while (top && top != script->native) {
GDMonoMethod *method = top->get_method(CACHED_STRING_NAME(_set), 2);
if (method) {
+ Variant name = p_name;
+ const Variant *args[2] = { &name, &p_value };
+
MonoObject *ret = method->invoke(mono_object, args);
if (ret && GDMonoMarshal::unbox<MonoBoolean>(ret) == true)
@@ -960,31 +1044,49 @@ bool CSharpInstance::get(const StringName &p_name, Variant &r_ret) const {
ERR_FAIL_COND_V(!script.is_valid(), false);
+ MonoObject *mono_object = get_mono_object();
+ ERR_FAIL_NULL_V(mono_object, false);
+
GDMonoClass *top = script->script_class;
while (top && top != script->native) {
GDMonoField *field = top->get_field(p_name);
if (field) {
- MonoObject *mono_object = get_mono_object();
+ MonoObject *value = field->get_value(mono_object);
+ r_ret = GDMonoMarshal::mono_object_to_variant(value);
+ return true;
+ }
- ERR_EXPLAIN("Reference has been garbage collected?");
- ERR_FAIL_NULL_V(mono_object, false);
+ GDMonoProperty *property = top->get_property(p_name);
- MonoObject *value = field->get_value(mono_object);
- r_ret = GDMonoMarshal::mono_object_to_variant(value, field->get_type());
+ if (property) {
+ MonoObject *exc = NULL;
+ MonoObject *value = property->get_value(mono_object, &exc);
+ if (exc) {
+ r_ret = Variant();
+ GDMonoUtils::print_unhandled_exception(exc);
+ } else {
+ r_ret = GDMonoMarshal::mono_object_to_variant(value);
+ }
return true;
}
- // Call _get
+ top = top->get_parent_class();
+ }
+
+ // Call _get
+ top = script->script_class;
+
+ while (top && top != script->native) {
GDMonoMethod *method = top->get_method(CACHED_STRING_NAME(_get), 1);
if (method) {
Variant name = p_name;
const Variant *args[1] = { &name };
- MonoObject *ret = method->invoke(get_mono_object(), args);
+ MonoObject *ret = method->invoke(mono_object, args);
if (ret) {
r_ret = GDMonoMarshal::mono_object_to_variant(ret);
@@ -1027,7 +1129,7 @@ bool CSharpInstance::has_method(const StringName &p_method) const {
GDMonoClass *top = script->script_class;
while (top && top != script->native) {
- if (top->has_method(p_method)) {
+ if (top->has_fetched_method_unknown_params(p_method)) {
return true;
}
@@ -1041,10 +1143,13 @@ Variant CSharpInstance::call(const StringName &p_method, const Variant **p_args,
MonoObject *mono_object = get_mono_object();
- ERR_FAIL_NULL_V(mono_object, Variant());
+ if (!mono_object) {
+ r_error.error = Variant::CallError::CALL_ERROR_INSTANCE_IS_NULL;
+ ERR_FAIL_V(Variant());
+ }
if (!script.is_valid())
- return Variant();
+ ERR_FAIL_V(Variant());
GDMonoClass *top = script->script_class;
@@ -1054,8 +1159,10 @@ Variant CSharpInstance::call(const StringName &p_method, const Variant **p_args,
if (method) {
MonoObject *return_value = method->invoke(mono_object, p_args);
+ r_error.error = Variant::CallError::CALL_OK;
+
if (return_value) {
- return GDMonoMarshal::mono_object_to_variant(return_value, method->get_return_type());
+ return GDMonoMarshal::mono_object_to_variant(return_value);
} else {
return Variant();
}
@@ -1186,24 +1293,29 @@ bool CSharpInstance::refcount_decremented() {
return ref_dying;
}
+ScriptInstance::RPCMode CSharpInstance::_member_get_rpc_mode(GDMonoClassMember *p_member) const {
+
+ if (p_member->has_attribute(CACHED_CLASS(RemoteAttribute)))
+ return RPC_MODE_REMOTE;
+ if (p_member->has_attribute(CACHED_CLASS(SyncAttribute)))
+ return RPC_MODE_SYNC;
+ if (p_member->has_attribute(CACHED_CLASS(MasterAttribute)))
+ return RPC_MODE_MASTER;
+ if (p_member->has_attribute(CACHED_CLASS(SlaveAttribute)))
+ return RPC_MODE_SLAVE;
+
+ return RPC_MODE_DISABLED;
+}
+
ScriptInstance::RPCMode CSharpInstance::get_rpc_mode(const StringName &p_method) const {
GDMonoClass *top = script->script_class;
while (top && top != script->native) {
- GDMonoMethod *method = top->get_method(p_method);
-
- if (method) { // TODO should we reject static methods?
- // TODO cache result
- if (method->has_attribute(CACHED_CLASS(RemoteAttribute)))
- return RPC_MODE_REMOTE;
- if (method->has_attribute(CACHED_CLASS(SyncAttribute)))
- return RPC_MODE_SYNC;
- if (method->has_attribute(CACHED_CLASS(MasterAttribute)))
- return RPC_MODE_MASTER;
- if (method->has_attribute(CACHED_CLASS(SlaveAttribute)))
- return RPC_MODE_SLAVE;
- }
+ GDMonoMethod *method = top->get_fetched_method_unknown_params(p_method);
+
+ if (method && !method->is_static())
+ return _member_get_rpc_mode(method);
top = top->get_parent_class();
}
@@ -1218,17 +1330,13 @@ ScriptInstance::RPCMode CSharpInstance::get_rset_mode(const StringName &p_variab
while (top && top != script->native) {
GDMonoField *field = top->get_field(p_variable);
- if (field) { // TODO should we reject static fields?
- // TODO cache result
- if (field->has_attribute(CACHED_CLASS(RemoteAttribute)))
- return RPC_MODE_REMOTE;
- if (field->has_attribute(CACHED_CLASS(SyncAttribute)))
- return RPC_MODE_SYNC;
- if (field->has_attribute(CACHED_CLASS(MasterAttribute)))
- return RPC_MODE_MASTER;
- if (field->has_attribute(CACHED_CLASS(SlaveAttribute)))
- return RPC_MODE_SLAVE;
- }
+ if (field && !field->is_static())
+ return _member_get_rpc_mode(field);
+
+ GDMonoProperty *property = top->get_property(p_variable);
+
+ if (property && !property->is_static())
+ return _member_get_rpc_mode(property);
top = top->get_parent_class();
}
@@ -1353,7 +1461,7 @@ bool CSharpScript::_update_exports() {
// We are creating a temporary new instance of the class here to get the default value
// TODO Workaround. Should be replaced with IL opcodes analysis
- MonoObject *tmp_object = mono_object_new(SCRIPTS_DOMAIN, script_class->get_raw());
+ MonoObject *tmp_object = mono_object_new(SCRIPTS_DOMAIN, script_class->get_mono_ptr());
if (tmp_object) {
CACHED_FIELD(GodotObject, ptr)->set_value_raw(tmp_object, tmp_object); // FIXME WTF is this workaround
@@ -1376,65 +1484,55 @@ bool CSharpScript::_update_exports() {
GDMonoClass *top = script_class;
while (top && top != native) {
+ PropertyInfo prop_info;
+ bool exported;
+
const Vector<GDMonoField *> &fields = top->get_all_fields();
for (int i = fields.size() - 1; i >= 0; i--) {
GDMonoField *field = fields[i];
- if (field->is_static()) {
- if (field->has_attribute(CACHED_CLASS(ExportAttribute)))
- ERR_PRINTS("Cannot export field because it is static: " + top->get_full_name() + "." + field->get_name());
- continue;
- }
-
- String name = field->get_name();
- StringName cname = name;
+ if (_get_member_export(top, field, prop_info, exported)) {
+ StringName name = field->get_name();
- if (member_info.has(cname))
- continue;
+ if (exported) {
+ member_info[name] = prop_info;
+ exported_members_cache.push_front(prop_info);
- ManagedType field_type = field->get_type();
- Variant::Type type = GDMonoMarshal::managed_to_variant_type(field_type);
+ if (tmp_object) {
+ exported_members_defval_cache[name] = GDMonoMarshal::mono_object_to_variant(field->get_value(tmp_object));
+ }
+ } else {
+ member_info[name] = prop_info;
+ }
+ }
+ }
- if (field->has_attribute(CACHED_CLASS(ExportAttribute))) {
- // Field has Export attribute
- MonoObject *attr = field->get_attribute(CACHED_CLASS(ExportAttribute));
+ const Vector<GDMonoProperty *> &properties = top->get_all_properties();
- PropertyHint hint;
- String hint_string;
+ for (int i = properties.size() - 1; i >= 0; i--) {
+ GDMonoProperty *property = properties[i];
- if (type == Variant::NIL) {
- ERR_PRINTS("Unknown type of exported field: " + top->get_full_name() + "." + field->get_name());
- continue;
- } else if (type == Variant::INT && field_type.type_encoding == MONO_TYPE_VALUETYPE && mono_class_is_enum(field_type.type_class->get_raw())) {
- type = Variant::INT;
- hint = PROPERTY_HINT_ENUM;
+ if (_get_member_export(top, property, prop_info, exported)) {
+ StringName name = property->get_name();
- Vector<MonoClassField *> fields = field_type.type_class->get_enum_fields();
+ if (exported) {
+ member_info[name] = prop_info;
+ exported_members_cache.push_front(prop_info);
- for (int i = 0; i < fields.size(); i++) {
- if (i > 0)
- hint_string += ",";
- hint_string += mono_field_get_name(fields[i]);
+ if (tmp_object) {
+ MonoObject *exc = NULL;
+ MonoObject *ret = property->get_value(tmp_object, &exc);
+ if (exc) {
+ exported_members_defval_cache[name] = Variant();
+ GDMonoUtils::print_unhandled_exception(exc);
+ } else {
+ exported_members_defval_cache[name] = GDMonoMarshal::mono_object_to_variant(ret);
+ }
}
- } else if (type == Variant::OBJECT && CACHED_CLASS(GodotReference)->is_assignable_from(field_type.type_class)) {
- hint = PROPERTY_HINT_RESOURCE_TYPE;
- hint_string = NATIVE_GDMONOCLASS_NAME(field_type.type_class);
} else {
- hint = PropertyHint(CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr));
- hint_string = CACHED_FIELD(ExportAttribute, hintString)->get_string_value(attr);
+ member_info[name] = prop_info;
}
-
- PropertyInfo prop_info = PropertyInfo(type, name, hint, hint_string, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE);
-
- member_info[cname] = prop_info;
- exported_members_cache.push_front(prop_info);
-
- if (tmp_object) {
- exported_members_defval_cache[cname] = GDMonoMarshal::mono_object_to_variant(field->get_value(tmp_object));
- }
- } else {
- member_info[cname] = PropertyInfo(type, name, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_SCRIPT_VARIABLE);
}
}
@@ -1458,6 +1556,79 @@ bool CSharpScript::_update_exports() {
return false;
}
+#ifdef TOOLS_ENABLED
+bool CSharpScript::_get_member_export(GDMonoClass *p_class, GDMonoClassMember *p_member, PropertyInfo &r_prop_info, bool &r_exported) {
+
+ StringName name = p_member->get_name();
+
+ if (p_member->is_static()) {
+ if (p_member->has_attribute(CACHED_CLASS(ExportAttribute)))
+ ERR_PRINTS("Cannot export member because it is static: " + p_class->get_full_name() + "." + name.operator String());
+ return false;
+ }
+
+ if (member_info.has(name))
+ return false;
+
+ ManagedType type;
+
+ if (p_member->get_member_type() == GDMonoClassMember::MEMBER_TYPE_FIELD) {
+ type = static_cast<GDMonoField *>(p_member)->get_type();
+ } else if (p_member->get_member_type() == GDMonoClassMember::MEMBER_TYPE_PROPERTY) {
+ type = static_cast<GDMonoProperty *>(p_member)->get_type();
+ } else {
+ CRASH_NOW();
+ }
+
+ Variant::Type variant_type = GDMonoMarshal::managed_to_variant_type(type);
+
+ if (p_member->has_attribute(CACHED_CLASS(ExportAttribute))) {
+ if (p_member->get_member_type() == GDMonoClassMember::MEMBER_TYPE_PROPERTY) {
+ GDMonoProperty *property = static_cast<GDMonoProperty *>(p_member);
+ if (!property->has_getter() || !property->has_setter()) {
+ ERR_PRINTS("Cannot export property because it does not provide a getter or a setter: " + p_class->get_full_name() + "." + name.operator String());
+ return false;
+ }
+ }
+
+ MonoObject *attr = p_member->get_attribute(CACHED_CLASS(ExportAttribute));
+
+ PropertyHint hint;
+ String hint_string;
+
+ if (variant_type == Variant::NIL) {
+ ERR_PRINTS("Unknown type of exported member: " + p_class->get_full_name() + "." + name.operator String());
+ return false;
+ } else if (variant_type == Variant::INT && type.type_encoding == MONO_TYPE_VALUETYPE && mono_class_is_enum(type.type_class->get_mono_ptr())) {
+ variant_type = Variant::INT;
+ hint = PROPERTY_HINT_ENUM;
+
+ Vector<MonoClassField *> fields = type.type_class->get_enum_fields();
+
+ for (int i = 0; i < fields.size(); i++) {
+ if (i > 0)
+ hint_string += ",";
+ hint_string += mono_field_get_name(fields[i]);
+ }
+ } else if (variant_type == Variant::OBJECT && CACHED_CLASS(GodotReference)->is_assignable_from(type.type_class)) {
+ hint = PROPERTY_HINT_RESOURCE_TYPE;
+ hint_string = NATIVE_GDMONOCLASS_NAME(type.type_class);
+ } else {
+ hint = PropertyHint(CACHED_FIELD(ExportAttribute, hint)->get_int_value(attr));
+ hint_string = CACHED_FIELD(ExportAttribute, hintString)->get_string_value(attr);
+ }
+
+ r_prop_info = PropertyInfo(variant_type, name.operator String(), hint, hint_string, PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE);
+ r_exported = true;
+ } else {
+ r_prop_info = PropertyInfo(variant_type, name.operator String(), PROPERTY_HINT_NONE, "", PROPERTY_USAGE_SCRIPT_VARIABLE);
+ r_exported = false;
+ }
+
+ return true;
+}
+#endif
+
void CSharpScript::_clear() {
tool = false;
@@ -1479,7 +1650,7 @@ Variant CSharpScript::call(const StringName &p_method, const Variant **p_args, i
MonoObject *result = method->invoke(NULL, p_args);
if (result) {
- return GDMonoMarshal::mono_object_to_variant(result, method->get_return_type());
+ return GDMonoMarshal::mono_object_to_variant(result);
} else {
return Variant();
}
@@ -1526,7 +1697,7 @@ bool CSharpScript::_set(const StringName &p_name, const Variant &p_value) {
void CSharpScript::_get_property_list(List<PropertyInfo> *p_properties) const {
- p_properties->push_back(PropertyInfo(Variant::STRING, CSharpLanguage::singleton->string_names._script_source, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR));
+ p_properties->push_back(PropertyInfo(Variant::STRING, CSharpLanguage::singleton->string_names._script_source, PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL));
}
void CSharpScript::_bind_methods() {
@@ -1626,7 +1797,7 @@ CSharpInstance *CSharpScript::_create_instance(const Variant **p_args, int p_arg
/* STEP 2, INITIALIZE AND CONSTRUCT */
- MonoObject *mono_object = mono_object_new(SCRIPTS_DOMAIN, script_class->get_raw());
+ MonoObject *mono_object = mono_object_new(SCRIPTS_DOMAIN, script_class->get_mono_ptr());
if (!mono_object) {
instance->script = Ref<CSharpScript>();
@@ -1764,7 +1935,7 @@ void CSharpScript::set_source_code(const String &p_code) {
bool CSharpScript::has_method(const StringName &p_method) const {
- return script_class->has_method(p_method);
+ return script_class->has_fetched_method_unknown_params(p_method);
}
Error CSharpScript::reload(bool p_keep_state) {
diff --git a/modules/mono/csharp_script.h b/modules/mono/csharp_script.h
index 27e68a7a56..1daa25b74e 100644
--- a/modules/mono/csharp_script.h
+++ b/modules/mono/csharp_script.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef CSHARP_SCRIPT_H
#define CSHARP_SCRIPT_H
@@ -104,6 +105,10 @@ class CSharpScript : public Script {
void _clear();
bool _update_exports();
+#ifdef TOOLS_ENABLED
+ bool _get_member_export(GDMonoClass *p_class, GDMonoClassMember *p_member, PropertyInfo &r_prop_info, bool &r_exported);
+#endif
+
CSharpInstance *_create_instance(const Variant **p_args, int p_argcount, Object *p_owner, bool p_isref, Variant::CallError &r_error);
Variant _new(const Variant **p_args, int p_argcount, Variant::CallError &r_error);
@@ -178,6 +183,8 @@ class CSharpInstance : public ScriptInstance {
void _call_multilevel(MonoObject *p_mono_object, const StringName &p_method, const Variant **p_args, int p_argcount);
+ RPCMode _member_get_rpc_mode(GDMonoClassMember *p_member) const;
+
public:
MonoObject *get_mono_object() const;
@@ -298,7 +305,7 @@ public:
/* TODO */ virtual void debug_get_stack_level_members(int p_level, List<String> *p_members, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {}
/* TODO */ virtual void debug_get_globals(List<String> *p_locals, List<Variant> *p_values, int p_max_subitems, int p_max_depth) {}
/* TODO */ virtual String debug_parse_stack_level_expression(int p_level, const String &p_expression, int p_max_subitems, int p_max_depth) { return ""; }
- /* TODO */ virtual Vector<StackInfo> debug_get_current_stack_info() { return Vector<StackInfo>(); }
+ virtual Vector<StackInfo> debug_get_current_stack_info();
/* PROFILING FUNCTIONS */
/* TODO */ virtual void profiling_start() {}
@@ -330,6 +337,10 @@ public:
virtual void *alloc_instance_binding_data(Object *p_object);
virtual void free_instance_binding_data(void *p_data);
+#ifdef DEBUG_ENABLED
+ Vector<StackInfo> stack_trace_get_info(MonoObject *p_stack_trace);
+#endif
+
CSharpLanguage();
~CSharpLanguage();
};
diff --git a/modules/mono/doc_classes/@C#.xml b/modules/mono/doc_classes/@C#.xml
index 5fcbf36a2b..0f33c76eb2 100644
--- a/modules/mono/doc_classes/@C#.xml
+++ b/modules/mono/doc_classes/@C#.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="@C#" category="Core" version="3.0-beta">
+<class name="@C#" category="Core" version="3.0-stable">
<brief_description>
</brief_description>
<description>
diff --git a/modules/mono/doc_classes/CSharpScript.xml b/modules/mono/doc_classes/CSharpScript.xml
index 853ef28731..3efe71f1b3 100644
--- a/modules/mono/doc_classes/CSharpScript.xml
+++ b/modules/mono/doc_classes/CSharpScript.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="CSharpScript" inherits="Script" category="Core" version="3.0-beta">
+<class name="CSharpScript" inherits="Script" category="Core" version="3.0-stable">
<brief_description>
</brief_description>
<description>
diff --git a/modules/mono/doc_classes/GodotSharp.xml b/modules/mono/doc_classes/GodotSharp.xml
index 2696a0bb4b..1e5edf2a2a 100644
--- a/modules/mono/doc_classes/GodotSharp.xml
+++ b/modules/mono/doc_classes/GodotSharp.xml
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
-<class name="GodotSharp" inherits="Object" category="Core" version="3.0-beta">
+<class name="GodotSharp" inherits="Object" category="Core" version="3.0-stable">
<brief_description>
</brief_description>
<description>
diff --git a/modules/mono/editor/bindings_generator.cpp b/modules/mono/editor/bindings_generator.cpp
index 0e41e00f30..62c7a94755 100644
--- a/modules/mono/editor/bindings_generator.cpp
+++ b/modules/mono/editor/bindings_generator.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "bindings_generator.h"
#ifdef DEBUG_METHODS_ENABLED
@@ -249,8 +250,15 @@ void BindingsGenerator::_generate_method_icalls(const TypeInterface &p_itype) {
const TypeInterface *return_type = _get_type_by_name_or_placeholder(imethod.return_type);
- String im_sig = "IntPtr " CS_PARAM_METHODBIND ", IntPtr " CS_PARAM_INSTANCE;
- String im_unique_sig = imethod.return_type.operator String() + ",IntPtr,IntPtr";
+ String im_sig;
+ String im_unique_sig;
+
+ if (p_itype.is_object_type) {
+ im_sig += "IntPtr " CS_PARAM_METHODBIND ", ";
+ im_unique_sig += imethod.return_type.operator String() + ",IntPtr,IntPtr";
+ }
+
+ im_sig += "IntPtr " CS_PARAM_INSTANCE;
// Get arguments information
int i = 0;
@@ -262,25 +270,37 @@ void BindingsGenerator::_generate_method_icalls(const TypeInterface &p_itype) {
im_sig += " arg";
im_sig += itos(i + 1);
- im_unique_sig += ",";
- im_unique_sig += get_unique_sig(*arg_type);
+ if (p_itype.is_object_type) {
+ im_unique_sig += ",";
+ im_unique_sig += get_unique_sig(*arg_type);
+ }
i++;
}
- // godot_icall_{argc}_{icallcount}
- String icall_method = ICALL_PREFIX + itos(imethod.arguments.size()) + "_" + itos(method_icalls.size());
+ String icall_method = ICALL_PREFIX;
+
+ if (p_itype.is_object_type) {
+ icall_method += itos(imethod.arguments.size()) + "_" + itos(method_icalls.size()); // godot_icall_{argc}_{icallcount}
+ } else {
+ icall_method += p_itype.name + "_" + imethod.name; // godot_icall_{Type}_{method}
+ }
InternalCall im_icall = InternalCall(p_itype.api_type, icall_method, return_type->im_type_out, im_sig, im_unique_sig);
- List<InternalCall>::Element *match = method_icalls.find(im_icall);
+ if (p_itype.is_object_type) {
+ List<InternalCall>::Element *match = method_icalls.find(im_icall);
- if (match) {
- if (p_itype.api_type != ClassDB::API_EDITOR)
- match->get().editor_only = false;
- method_icalls_map.insert(&E->get(), &match->get());
+ if (match) {
+ if (p_itype.api_type != ClassDB::API_EDITOR)
+ match->get().editor_only = false;
+ method_icalls_map.insert(&E->get(), &match->get());
+ } else {
+ List<InternalCall>::Element *added = method_icalls.push_back(im_icall);
+ method_icalls_map.insert(&E->get(), &added->get());
+ }
} else {
- List<InternalCall>::Element *added = method_icalls.push_back(im_icall);
+ List<InternalCall>::Element *added = builtin_method_icalls.push_back(im_icall);
method_icalls_map.insert(&E->get(), &added->get());
}
}
@@ -447,14 +467,14 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_output_dir, bo
compile_items.push_back(output_file);
}
- for (Map<StringName, TypeInterface>::Element *E = obj_types.front(); E; E = E->next()) {
- const TypeInterface &itype = E->get();
+ for (OrderedHashMap<StringName, TypeInterface>::Element E = obj_types.front(); E; E = E.next()) {
+ const TypeInterface &itype = E.get();
if (itype.api_type == ClassDB::API_EDITOR)
continue;
- String output_file = path_join(obj_type_dir, E->get().proxy_name + ".cs");
- Error err = _generate_cs_type(E->get(), output_file);
+ String output_file = path_join(obj_type_dir, itype.proxy_name + ".cs");
+ Error err = _generate_cs_type(itype, output_file);
if (err == ERR_SKIP)
continue;
@@ -524,6 +544,8 @@ Error BindingsGenerator::generate_cs_core_project(const String &p_output_dir, bo
ADD_INTERNAL_CALL(E->get());
for (const List<InternalCall>::Element *E = method_icalls.front(); E; E = E->next())
ADD_INTERNAL_CALL(E->get());
+ for (const List<InternalCall>::Element *E = builtin_method_icalls.front(); E; E = E->next())
+ ADD_INTERNAL_CALL(E->get());
#undef ADD_INTERNAL_CALL
@@ -579,14 +601,14 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_output_dir,
if (!solution.set_path(p_output_dir))
return ERR_FILE_NOT_FOUND;
- for (Map<StringName, TypeInterface>::Element *E = obj_types.front(); E; E = E->next()) {
- const TypeInterface &itype = E->get();
+ for (OrderedHashMap<StringName, TypeInterface>::Element E = obj_types.front(); E; E = E.next()) {
+ const TypeInterface &itype = E.get();
if (itype.api_type != ClassDB::API_EDITOR)
continue;
- String output_file = path_join(obj_type_dir, E->get().proxy_name + ".cs");
- Error err = _generate_cs_type(E->get(), output_file);
+ String output_file = path_join(obj_type_dir, itype.proxy_name + ".cs");
+ Error err = _generate_cs_type(itype, output_file);
if (err == ERR_SKIP)
continue;
@@ -615,6 +637,8 @@ Error BindingsGenerator::generate_cs_editor_project(const String &p_output_dir,
cs_icalls_content.push_back(m_icall.im_sig + ");\n"); \
}
+ // No need to add builtin_method_icalls. Builtin types are core only
+
for (const List<InternalCall>::Element *E = editor_custom_icalls.front(); E; E = E->next())
ADD_INTERNAL_CALL(E->get());
for (const List<InternalCall>::Element *E = method_icalls.front(); E; E = E->next())
@@ -693,9 +717,9 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
output.push_back(itype.is_singleton ? "static class " : "class ");
output.push_back(itype.proxy_name);
- if (itype.is_singleton || !itype.is_object_type) {
+ if (itype.is_singleton) {
output.push_back("\n");
- } else if (!is_derived_type) {
+ } else if (!is_derived_type || !itype.is_object_type /* assuming only object types inherit */) {
output.push_back(" : IDisposable\n");
} else if (obj_types.has(itype.base_name)) {
output.push_back(" : ");
@@ -837,7 +861,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
output.push_back(MEMBER_BEGIN "public void Dispose()\n" OPEN_BLOCK_L2 "Dispose(true);\n" INDENT3 "GC.SuppressFinalize(this);\n" CLOSE_BLOCK_L2);
// Add the virtual Dispose
- output.push_back(MEMBER_BEGIN "public virtual void Dispose(bool disposing)\n" OPEN_BLOCK_L2
+ output.push_back(MEMBER_BEGIN "protected virtual void Dispose(bool disposing)\n" OPEN_BLOCK_L2
"if (disposed) return;\n" INDENT3
"if (" BINDINGS_PTR_FIELD " != IntPtr.Zero)\n" OPEN_BLOCK_L3 "NativeCalls.godot_icall_");
output.push_back(itype.proxy_name);
@@ -928,7 +952,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
output.push_back(MEMBER_BEGIN "public void Dispose()\n" OPEN_BLOCK_L2 "Dispose(true);\n" INDENT3 "GC.SuppressFinalize(this);\n" CLOSE_BLOCK_L2);
// Add the virtual Dispose
- output.push_back(MEMBER_BEGIN "public virtual void Dispose(bool disposing)\n" OPEN_BLOCK_L2
+ output.push_back(MEMBER_BEGIN "protected virtual void Dispose(bool disposing)\n" OPEN_BLOCK_L2
"if (disposed) return;\n" INDENT3
"if (" BINDINGS_PTR_FIELD " != IntPtr.Zero)\n" OPEN_BLOCK_L3
"if (" CS_FIELD_MEMORYOWN ")\n" OPEN_BLOCK_L4 CS_FIELD_MEMORYOWN
@@ -944,7 +968,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
return ERR_BUG;
}
- Map<StringName, TypeInterface>::Element *object_itype = obj_types.find("Object");
+ OrderedHashMap<StringName, TypeInterface>::Element object_itype = obj_types.find("Object");
if (!object_itype) {
ERR_PRINT("BUG: Object type interface not found!");
@@ -952,7 +976,7 @@ Error BindingsGenerator::_generate_cs_type(const TypeInterface &itype, const Str
}
output.push_back(MEMBER_BEGIN "public " CS_CLASS_SIGNALAWAITER " ToSignal(");
- output.push_back(object_itype->get().cs_type);
+ output.push_back(object_itype.get().cs_type);
output.push_back(" source, string signal)\n" OPEN_BLOCK_L2
"return new " CS_CLASS_SIGNALAWAITER "(source, signal, this);\n" CLOSE_BLOCK_L2);
}
@@ -998,9 +1022,9 @@ Error BindingsGenerator::_generate_cs_property(const BindingsGenerator::TypeInte
// Search it in base types too
const TypeInterface *current_type = &p_itype;
while (!setter && current_type->base_name != StringName()) {
- Map<StringName, TypeInterface>::Element *base_match = obj_types.find(current_type->base_name);
- ERR_FAIL_NULL_V(base_match, ERR_BUG);
- current_type = &base_match->get();
+ OrderedHashMap<StringName, TypeInterface>::Element base_match = obj_types.find(current_type->base_name);
+ ERR_FAIL_COND_V(!base_match, ERR_BUG);
+ current_type = &base_match.get();
setter = current_type->find_method_by_name(p_iprop.setter);
}
@@ -1009,9 +1033,9 @@ Error BindingsGenerator::_generate_cs_property(const BindingsGenerator::TypeInte
// Search it in base types too
current_type = &p_itype;
while (!getter && current_type->base_name != StringName()) {
- Map<StringName, TypeInterface>::Element *base_match = obj_types.find(current_type->base_name);
- ERR_FAIL_NULL_V(base_match, ERR_BUG);
- current_type = &base_match->get();
+ OrderedHashMap<StringName, TypeInterface>::Element base_match = obj_types.find(current_type->base_name);
+ ERR_FAIL_COND_V(!base_match, ERR_BUG);
+ current_type = &base_match.get();
getter = current_type->find_method_by_name(p_iprop.getter);
}
@@ -1121,10 +1145,14 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf
String method_bind_field = "method_bind_" + itos(p_method_bind_count);
- String icall_params = method_bind_field + ", " + sformat(p_itype.cs_in, "this");
String arguments_sig;
String cs_in_statements;
+ String icall_params;
+ if (p_itype.is_object_type)
+ icall_params += method_bind_field + ", ";
+ icall_params += sformat(p_itype.cs_in, "this");
+
List<String> default_args_doc;
// Retrieve information from the arguments
@@ -1199,9 +1227,8 @@ Error BindingsGenerator::_generate_cs_method(const BindingsGenerator::TypeInterf
// Generate method
{
- if (!p_imethod.is_virtual && !p_imethod.requires_object_call) {
- p_output.push_back(MEMBER_BEGIN "private ");
- p_output.push_back(p_itype.is_singleton ? "static IntPtr " : "IntPtr ");
+ if (p_itype.is_object_type && !p_imethod.is_virtual && !p_imethod.requires_object_call) {
+ p_output.push_back(MEMBER_BEGIN "private static IntPtr ");
p_output.push_back(method_bind_field + " = " CS_CLASS_NATIVECALLS "." ICALL_GET_METHODBIND "(" BINDINGS_NATIVE_NAME_FIELD ", \"");
p_output.push_back(p_imethod.name);
p_output.push_back("\");\n");
@@ -1323,8 +1350,8 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) {
generated_icall_funcs.clear();
- for (Map<StringName, TypeInterface>::Element *type_elem = obj_types.front(); type_elem; type_elem = type_elem->next()) {
- const TypeInterface &itype = type_elem->get();
+ for (OrderedHashMap<StringName, TypeInterface>::Element type_elem = obj_types.front(); type_elem; type_elem = type_elem.next()) {
+ const TypeInterface &itype = type_elem.get();
List<InternalCall> &custom_icalls = itype.api_type == ClassDB::API_EDITOR ? editor_custom_icalls : core_custom_icalls;
@@ -1380,6 +1407,7 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) {
output.push_back(itos(GDMono::get_singleton()->get_api_editor_hash()) +
"; }\n#endif // TOOLS_ENABLED\n");
output.push_back("void register_generated_icalls() " OPEN_BLOCK);
+ output.push_back("\tgodot_register_header_icalls();");
#define ADD_INTERNAL_CALL_REGISTRATION(m_icall) \
{ \
@@ -1442,6 +1470,9 @@ Error BindingsGenerator::generate_glue(const String &p_output_dir) {
output.push_back("#endif\n");
}
+ for (const List<InternalCall>::Element *E = builtin_method_icalls.front(); E; E = E->next())
+ ADD_INTERNAL_CALL_REGISTRATION(E->get());
+
#undef ADD_INTERNAL_CALL_REGISTRATION
output.push_back(CLOSE_BLOCK "}\n");
@@ -1517,6 +1548,9 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte
i++;
}
+ if (!p_itype.is_object_type)
+ return OK; // no auto-generated icall functions for builtin types
+
const Map<const MethodInterface *, const InternalCall *>::Element *match = method_icalls_map.find(&p_imethod);
ERR_FAIL_NULL_V(match, ERR_BUG);
@@ -1630,20 +1664,20 @@ Error BindingsGenerator::_generate_glue_method(const BindingsGenerator::TypeInte
const BindingsGenerator::TypeInterface *BindingsGenerator::_get_type_by_name_or_null(const StringName &p_cname) {
- const Map<StringName, TypeInterface>::Element *match = builtin_types.find(p_cname);
+ const Map<StringName, TypeInterface>::Element *builtin_type_match = builtin_types.find(p_cname);
- if (match)
- return &match->get();
+ if (builtin_type_match)
+ return &builtin_type_match->get();
- match = obj_types.find(p_cname);
+ const OrderedHashMap<StringName, TypeInterface>::Element obj_type_match = obj_types.find(p_cname);
- if (match)
- return &match->get();
+ if (obj_type_match)
+ return &obj_type_match.get();
- match = enum_types.find(p_cname);
+ const Map<StringName, TypeInterface>::Element *enum_match = enum_types.find(p_cname);
- if (match)
- return &match->get();
+ if (enum_match)
+ return &enum_match->get();
return NULL;
}
@@ -1810,7 +1844,7 @@ void BindingsGenerator::_populate_object_type_interfaces() {
imethod.return_type = name_cache.type_void;
// Actually, more methods like this may be added in the future,
- // which could actually will return something differnet.
+ // which could actually will return something different.
// Let's put this to notify us if that ever happens.
if (itype.cname != name_cache.type_Object || imethod.name != "free") {
if (verbose_output) {
@@ -2112,36 +2146,34 @@ void BindingsGenerator::_populate_builtin_type_interfaces() {
#undef INSERT_STRUCT_TYPE
-#define INSERT_PRIMITIVE_TYPE(m_type) \
- { \
- itype = TypeInterface::create_value_type(String(#m_type)); \
- itype.c_arg_in = "&%s"; \
- itype.c_type_in = #m_type; \
- itype.c_type_out = #m_type; \
- itype.im_type_in = #m_type; \
- itype.im_type_out = #m_type; \
- builtin_types.insert(itype.cname, itype); \
- }
-
- INSERT_PRIMITIVE_TYPE(bool)
- //INSERT_PRIMITIVE_TYPE(int)
+ // bool
+ itype = TypeInterface::create_value_type(String("bool"));
+ itype.c_arg_in = "&%s";
+ // /* MonoBoolean <---> bool
+ itype.c_in = "\t%0 %1_in = (%0)%1;\n";
+ itype.c_out = "\treturn (%0)%1;\n";
+ itype.c_type = "bool";
+ // */
+ itype.c_type_in = "MonoBoolean";
+ itype.c_type_out = itype.c_type_in;
+ itype.im_type_in = itype.name;
+ itype.im_type_out = itype.name;
+ builtin_types.insert(itype.cname, itype);
// int
itype = TypeInterface::create_value_type(String("int"));
itype.c_arg_in = "&%s_in";
- //* ptrcall only supports int64_t and uint64_t
+ // /* ptrcall only supports int64_t and uint64_t
itype.c_in = "\t%0 %1_in = (%0)%1;\n";
itype.c_out = "\treturn (%0)%1;\n";
itype.c_type = "int64_t";
- //*/
- itype.c_type_in = itype.name;
- itype.c_type_out = itype.name;
+ // */
+ itype.c_type_in = "int32_t";
+ itype.c_type_out = itype.c_type_in;
itype.im_type_in = itype.name;
itype.im_type_out = itype.name;
builtin_types.insert(itype.cname, itype);
-#undef INSERT_PRIMITIVE_TYPE
-
// real_t
itype = TypeInterface();
#ifdef REAL_T_IS_DOUBLE
@@ -2483,8 +2515,8 @@ void BindingsGenerator::initialize() {
_generate_header_icalls();
- for (Map<StringName, TypeInterface>::Element *E = obj_types.front(); E; E = E->next())
- _generate_method_icalls(E->get());
+ for (OrderedHashMap<StringName, TypeInterface>::Element E = obj_types.front(); E; E = E.next())
+ _generate_method_icalls(E.get());
_generate_method_icalls(builtin_types["NodePath"]);
_generate_method_icalls(builtin_types["RID"]);
diff --git a/modules/mono/editor/bindings_generator.h b/modules/mono/editor/bindings_generator.h
index 9da7add867..4ab8d86cf3 100644
--- a/modules/mono/editor/bindings_generator.h
+++ b/modules/mono/editor/bindings_generator.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef BINDINGS_GENERATOR_H
#define BINDINGS_GENERATOR_H
@@ -428,10 +429,11 @@ class BindingsGenerator {
static bool verbose_output;
+ OrderedHashMap<StringName, TypeInterface> obj_types;
+
Map<StringName, TypeInterface> placeholder_types;
Map<StringName, TypeInterface> builtin_types;
Map<StringName, TypeInterface> enum_types;
- Map<StringName, TypeInterface> obj_types;
List<EnumInterface> global_enums;
List<ConstantInterface> global_constants;
@@ -439,6 +441,7 @@ class BindingsGenerator {
Map<StringName, String> extra_members;
List<InternalCall> method_icalls;
+ List<InternalCall> builtin_method_icalls;
Map<const MethodInterface *, const InternalCall *> method_icalls_map;
List<const InternalCall *> generated_icall_funcs;
diff --git a/modules/mono/editor/csharp_project.cpp b/modules/mono/editor/csharp_project.cpp
index 89e72e5c4b..e4269b0aec 100644
--- a/modules/mono/editor/csharp_project.cpp
+++ b/modules/mono/editor/csharp_project.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "csharp_project.h"
#include "os/os.h"
diff --git a/modules/mono/editor/csharp_project.h b/modules/mono/editor/csharp_project.h
index 59277664b2..381dd17e02 100644
--- a/modules/mono/editor/csharp_project.h
+++ b/modules/mono/editor/csharp_project.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef CSHARP_PROJECT_H
#define CSHARP_PROJECT_H
diff --git a/modules/mono/editor/godotsharp_builds.cpp b/modules/mono/editor/godotsharp_builds.cpp
index 58d26a0f83..6b41b10981 100644
--- a/modules/mono/editor/godotsharp_builds.cpp
+++ b/modules/mono/editor/godotsharp_builds.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "godotsharp_builds.h"
#include "main/main.h"
@@ -446,7 +447,7 @@ void GodotSharpBuilds::BuildProcess::start(bool p_blocking) {
GDMonoClass *klass = GDMono::get_singleton()->get_editor_tools_assembly()->get_class("GodotSharpTools.Build", "BuildInstance");
- MonoObject *mono_object = mono_object_new(mono_domain_get(), klass->get_raw());
+ MonoObject *mono_object = mono_object_new(mono_domain_get(), klass->get_mono_ptr());
// Construct
diff --git a/modules/mono/editor/godotsharp_builds.h b/modules/mono/editor/godotsharp_builds.h
index 956f8f6253..5d2390ecd9 100644
--- a/modules/mono/editor/godotsharp_builds.h
+++ b/modules/mono/editor/godotsharp_builds.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GODOTSHARP_BUILDS_H
#define GODOTSHARP_BUILDS_H
diff --git a/modules/mono/editor/godotsharp_editor.cpp b/modules/mono/editor/godotsharp_editor.cpp
index f964fac8e9..0ef3adfdd0 100644
--- a/modules/mono/editor/godotsharp_editor.cpp
+++ b/modules/mono/editor/godotsharp_editor.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "godotsharp_editor.h"
#include "core/os/os.h"
@@ -111,6 +112,21 @@ void GodotSharpEditor::_remove_create_sln_menu_option() {
bottom_panel_btn->show();
}
+void GodotSharpEditor::_show_about_dialog() {
+
+ bool show_on_start = EDITOR_GET("mono/editor/show_info_on_start");
+ about_dialog_checkbox->set_pressed(show_on_start);
+ about_dialog->popup_centered_minsize();
+}
+
+void GodotSharpEditor::_toggle_about_dialog_on_start(bool p_enabled) {
+
+ bool show_on_start = EDITOR_GET("mono/editor/show_info_on_start");
+ if (show_on_start != p_enabled) {
+ EditorSettings::get_singleton()->set_setting("mono/editor/show_info_on_start", p_enabled);
+ }
+}
+
void GodotSharpEditor::_menu_option_pressed(int p_id) {
switch (p_id) {
@@ -118,15 +134,37 @@ void GodotSharpEditor::_menu_option_pressed(int p_id) {
_create_project_solution();
} break;
+ case MENU_ABOUT_CSHARP: {
+
+ _show_about_dialog();
+ } break;
default:
ERR_FAIL();
}
}
+void GodotSharpEditor::_notification(int p_notification) {
+
+ switch (p_notification) {
+
+ case NOTIFICATION_READY: {
+
+ bool show_info_dialog = EDITOR_GET("mono/editor/show_info_on_start");
+ if (show_info_dialog) {
+ about_dialog->set_exclusive(true);
+ _show_about_dialog();
+ // Once shown a first time, it can be seen again via the Mono menu - it doesn't have to be exclusive then.
+ about_dialog->set_exclusive(false);
+ }
+ }
+ }
+}
+
void GodotSharpEditor::_bind_methods() {
ClassDB::bind_method(D_METHOD("_create_project_solution"), &GodotSharpEditor::_create_project_solution);
ClassDB::bind_method(D_METHOD("_remove_create_sln_menu_option"), &GodotSharpEditor::_remove_create_sln_menu_option);
+ ClassDB::bind_method(D_METHOD("_toggle_about_dialog_on_start"), &GodotSharpEditor::_toggle_about_dialog_on_start);
ClassDB::bind_method(D_METHOD("_menu_option_pressed", "id"), &GodotSharpEditor::_menu_option_pressed);
}
@@ -150,7 +188,7 @@ Error GodotSharpEditor::open_in_external_editor(const Ref<Script> &p_script, int
if (p_line >= 0) {
args.push_back("-g");
- args.push_back(script_path + ":" + itos(p_line) + ":" + itos(p_col));
+ args.push_back(script_path + ":" + itos(p_line + 1) + ":" + itos(p_col));
} else {
args.push_back(script_path);
}
@@ -169,6 +207,11 @@ Error GodotSharpEditor::open_in_external_editor(const Ref<Script> &p_script, int
monodevel_instance = memnew(MonoDevelopInstance(GodotSharpDirs::get_project_sln_path()));
String script_path = ProjectSettings::get_singleton()->globalize_path(p_script->get_path());
+
+ if (p_line >= 0) {
+ script_path += ";" + itos(p_line + 1) + ";" + itos(p_col);
+ }
+
monodevel_instance->execute(script_path);
} break;
default:
@@ -204,6 +247,55 @@ GodotSharpEditor::GodotSharpEditor(EditorNode *p_editor) {
menu_button->set_text(TTR("Mono"));
menu_popup = menu_button->get_popup();
+ // TODO: Remove or edit this info dialog once Mono support is no longer in alpha
+ {
+ menu_popup->add_item(TTR("About C# support"), MENU_ABOUT_CSHARP);
+ about_dialog = memnew(AcceptDialog);
+ editor->get_gui_base()->add_child(about_dialog);
+ about_dialog->set_title("Important: C# support is not feature-complete");
+
+ // We don't use set_text() as the default AcceptDialog Label doesn't play well with the TextureRect and CheckBox
+ // we'll add. Instead we add containers and a new autowrapped Label inside.
+
+ // Main VBoxContainer (icon + label on top, checkbox at bottom)
+ VBoxContainer *about_vbc = memnew(VBoxContainer);
+ about_dialog->add_child(about_vbc);
+
+ // HBoxContainer for icon + label
+ HBoxContainer *about_hbc = memnew(HBoxContainer);
+ about_vbc->add_child(about_hbc);
+
+ TextureRect *about_icon = memnew(TextureRect);
+ about_hbc->add_child(about_icon);
+ Ref<Texture> about_icon_tex = about_icon->get_icon("NodeWarning", "EditorIcons");
+ about_icon->set_texture(about_icon_tex);
+
+ Label *about_label = memnew(Label);
+ about_hbc->add_child(about_label);
+ about_label->set_custom_minimum_size(Size2(600, 150) * EDSCALE);
+ about_label->set_v_size_flags(Control::SIZE_EXPAND_FILL);
+ about_label->set_autowrap(true);
+ String about_text =
+ String("C# support in Godot Engine is a brand new feature and a work in progress.\n") +
+ "It is at the alpha stage and thus not suitable for use in production.\n\n" +
+ "As of Godot 3.0, C# support is not feature-complete and can crash in some situations. " +
+ "Bugs and usability issues will be addressed gradually over 3.0.x and 3.x releases.\n" +
+ "The main missing feature is the ability to export games using C# assemblies - you will therefore be able to develop and run games in the editor, " +
+ "but not to share them as standalone binaries. This feature is of course high on the priority list and should be available in 3.0.1.\n\n" +
+ "If you experience issues with this Mono build, please report them on Godot's issue tracker with details about your system, Mono version, IDE, etc.:\n\n" +
+ " https://github.com/godotengine/godot/issues\n\n" +
+ "Your critical feedback at this stage will play a great role in shaping the C# support in future releases, so thank you!";
+ about_label->set_text(about_text);
+
+ EDITOR_DEF("mono/editor/show_info_on_start", true);
+
+ // CheckBox in main container
+ about_dialog_checkbox = memnew(CheckBox);
+ about_vbc->add_child(about_dialog_checkbox);
+ about_dialog_checkbox->set_text("Show this warning when starting the editor");
+ about_dialog_checkbox->connect("toggled", this, "_toggle_about_dialog_on_start");
+ }
+
String sln_path = GodotSharpDirs::get_project_sln_path();
String csproj_path = GodotSharpDirs::get_project_csproj_path();
diff --git a/modules/mono/editor/godotsharp_editor.h b/modules/mono/editor/godotsharp_editor.h
index f9b4fb42fb..81c49aec30 100644
--- a/modules/mono/editor/godotsharp_editor.h
+++ b/modules/mono/editor/godotsharp_editor.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GODOTSHARP_EDITOR_H
#define GODOTSHARP_EDITOR_H
@@ -43,6 +44,8 @@ class GodotSharpEditor : public Node {
PopupMenu *menu_popup;
AcceptDialog *error_dialog;
+ AcceptDialog *about_dialog;
+ CheckBox *about_dialog_checkbox;
ToolButton *bottom_panel_btn;
@@ -53,17 +56,21 @@ class GodotSharpEditor : public Node {
bool _create_project_solution();
void _remove_create_sln_menu_option();
+ void _show_about_dialog();
+ void _toggle_about_dialog_on_start(bool p_enabled);
void _menu_option_pressed(int p_id);
static GodotSharpEditor *singleton;
protected:
+ void _notification(int p_notification);
static void _bind_methods();
public:
enum MenuOptions {
- MENU_CREATE_SLN
+ MENU_CREATE_SLN,
+ MENU_ABOUT_CSHARP,
};
enum ExternalEditor {
diff --git a/modules/mono/editor/mono_bottom_panel.cpp b/modules/mono/editor/mono_bottom_panel.cpp
index 7c8d822037..43689548b5 100644
--- a/modules/mono/editor/mono_bottom_panel.cpp
+++ b/modules/mono/editor/mono_bottom_panel.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "mono_bottom_panel.h"
#include "../csharp_script.h"
diff --git a/modules/mono/editor/mono_bottom_panel.h b/modules/mono/editor/mono_bottom_panel.h
index d7573361ab..a44d3a9af8 100644
--- a/modules/mono/editor/mono_bottom_panel.h
+++ b/modules/mono/editor/mono_bottom_panel.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef MONO_BOTTOM_PANEL_H
#define MONO_BOTTOM_PANEL_H
diff --git a/modules/mono/editor/mono_build_info.h b/modules/mono/editor/mono_build_info.h
index 115fc9ea55..4806764a61 100644
--- a/modules/mono/editor/mono_build_info.h
+++ b/modules/mono/editor/mono_build_info.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef MONO_BUILD_INFO_H
#define MONO_BUILD_INFO_H
diff --git a/modules/mono/editor/monodevelop_instance.cpp b/modules/mono/editor/monodevelop_instance.cpp
index 57b3382bff..48a285561d 100644
--- a/modules/mono/editor/monodevelop_instance.cpp
+++ b/modules/mono/editor/monodevelop_instance.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "monodevelop_instance.h"
#include "../mono_gd/gd_mono.h"
@@ -34,6 +35,8 @@
void MonoDevelopInstance::execute(const Vector<String> &p_files) {
+ _GDMONO_SCOPE_DOMAIN_(TOOLS_DOMAIN)
+
ERR_FAIL_NULL(execute_method);
ERR_FAIL_COND(gc_handle.is_null());
@@ -62,7 +65,7 @@ MonoDevelopInstance::MonoDevelopInstance(const String &p_solution) {
GDMonoClass *klass = GDMono::get_singleton()->get_editor_tools_assembly()->get_class("GodotSharpTools.Editor", "MonoDevelopInstance");
- MonoObject *obj = mono_object_new(TOOLS_DOMAIN, klass->get_raw());
+ MonoObject *obj = mono_object_new(TOOLS_DOMAIN, klass->get_mono_ptr());
GDMonoMethod *ctor = klass->get_method(".ctor", 1);
MonoObject *ex = NULL;
diff --git a/modules/mono/editor/monodevelop_instance.h b/modules/mono/editor/monodevelop_instance.h
index 783d12325f..7e8a76b595 100644
--- a/modules/mono/editor/monodevelop_instance.h
+++ b/modules/mono/editor/monodevelop_instance.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef MONODEVELOP_INSTANCE_H
#define MONODEVELOP_INSTANCE_H
diff --git a/modules/mono/editor/net_solution.cpp b/modules/mono/editor/net_solution.cpp
index b9df5b5327..dab96e44e9 100644
--- a/modules/mono/editor/net_solution.cpp
+++ b/modules/mono/editor/net_solution.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "net_solution.h"
#include "os/dir_access.h"
diff --git a/modules/mono/editor/net_solution.h b/modules/mono/editor/net_solution.h
index 21af1938cb..293e86917a 100644
--- a/modules/mono/editor/net_solution.h
+++ b/modules/mono/editor/net_solution.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef NET_SOLUTION_H
#define NET_SOLUTION_H
diff --git a/modules/mono/glue/builtin_types_glue.h b/modules/mono/glue/builtin_types_glue.h
new file mode 100644
index 0000000000..460de84b65
--- /dev/null
+++ b/modules/mono/glue/builtin_types_glue.h
@@ -0,0 +1,59 @@
+#ifndef BUILTIN_TYPES_GLUE_H
+#define BUILTIN_TYPES_GLUE_H
+
+#include "core/node_path.h"
+#include "core/rid.h"
+
+#include <mono/metadata/object.h>
+
+#include "../mono_gd/gd_mono_marshal.h"
+
+MonoBoolean godot_icall_NodePath_is_absolute(NodePath *p_ptr) {
+ return (MonoBoolean)p_ptr->is_absolute();
+}
+
+uint32_t godot_icall_NodePath_get_name_count(NodePath *p_ptr) {
+ return p_ptr->get_name_count();
+}
+
+MonoString *godot_icall_NodePath_get_name(NodePath *p_ptr, uint32_t p_idx) {
+ return GDMonoMarshal::mono_string_from_godot(p_ptr->get_name(p_idx));
+}
+
+uint32_t godot_icall_NodePath_get_subname_count(NodePath *p_ptr) {
+ return p_ptr->get_subname_count();
+}
+
+MonoString *godot_icall_NodePath_get_subname(NodePath *p_ptr, uint32_t p_idx) {
+ return GDMonoMarshal::mono_string_from_godot(p_ptr->get_subname(p_idx));
+}
+
+MonoString *godot_icall_NodePath_get_concatenated_subnames(NodePath *p_ptr) {
+ return GDMonoMarshal::mono_string_from_godot(p_ptr->get_concatenated_subnames());
+}
+
+NodePath *godot_icall_NodePath_get_as_property_path(NodePath *p_ptr) {
+ return memnew(NodePath(p_ptr->get_as_property_path()));
+}
+
+MonoBoolean godot_icall_NodePath_is_empty(NodePath *p_ptr) {
+ return (MonoBoolean)p_ptr->is_empty();
+}
+
+uint32_t godot_icall_RID_get_id(RID *p_ptr) {
+ return p_ptr->get_id();
+}
+
+void godot_register_builtin_type_icalls() {
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_get_as_property_path", (void *)godot_icall_NodePath_get_as_property_path);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_get_concatenated_subnames", (void *)godot_icall_NodePath_get_concatenated_subnames);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_get_name", (void *)godot_icall_NodePath_get_name);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_get_name_count", (void *)godot_icall_NodePath_get_name_count);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_get_subname", (void *)godot_icall_NodePath_get_subname);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_get_subname_count", (void *)godot_icall_NodePath_get_subname_count);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_is_absolute", (void *)godot_icall_NodePath_is_absolute);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_NodePath_is_empty", (void *)godot_icall_NodePath_is_empty);
+ mono_add_internal_call("Godot.NativeCalls::godot_icall_RID_get_id", (void *)godot_icall_RID_get_id);
+}
+
+#endif // BUILTIN_TYPES_GLUE_H
diff --git a/modules/mono/glue/cs_files/Color.cs b/modules/mono/glue/cs_files/Color.cs
index db0e1fb744..f9e31e9703 100644
--- a/modules/mono/glue/cs_files/Color.cs
+++ b/modules/mono/glue/cs_files/Color.cs
@@ -336,7 +336,7 @@ namespace Godot
this.r = (rgba & 0xFF) / 255.0f;
}
- private static float _parse_col(string str, int ofs)
+ private static int _parse_col(string str, int ofs)
{
int ig = 0;
@@ -415,17 +415,17 @@ namespace Godot
if (alpha)
{
- if ((int)_parse_col(color, 0) < 0)
+ if (_parse_col(color, 0) < 0)
return false;
}
int from = alpha ? 2 : 0;
- if ((int)_parse_col(color, from + 0) < 0)
+ if (_parse_col(color, from + 0) < 0)
return false;
- if ((int)_parse_col(color, from + 2) < 0)
+ if (_parse_col(color, from + 2) < 0)
return false;
- if ((int)_parse_col(color, from + 4) < 0)
+ if (_parse_col(color, from + 4) < 0)
return false;
return true;
@@ -467,10 +467,10 @@ namespace Godot
if (alpha)
{
- a = _parse_col(rgba, 0);
+ a = _parse_col(rgba, 0) / 255f;
if (a < 0)
- throw new ArgumentOutOfRangeException("Invalid color code. Alpha is " + a + " but zero or greater is expected: " + rgba);
+ throw new ArgumentOutOfRangeException("Invalid color code. Alpha part is not valid hexadecimal: " + rgba);
}
else
{
@@ -479,20 +479,20 @@ namespace Godot
int from = alpha ? 2 : 0;
- r = _parse_col(rgba, from + 0);
+ r = _parse_col(rgba, from + 0) / 255f;
if (r < 0)
- throw new ArgumentOutOfRangeException("Invalid color code. Red is " + r + " but zero or greater is expected: " + rgba);
+ throw new ArgumentOutOfRangeException("Invalid color code. Red part is not valid hexadecimal: " + rgba);
- g = _parse_col(rgba, from + 2);
+ g = _parse_col(rgba, from + 2) / 255f;
if (g < 0)
- throw new ArgumentOutOfRangeException("Invalid color code. Green is " + g + " but zero or greater is expected: " + rgba);
+ throw new ArgumentOutOfRangeException("Invalid color code. Green part is not valid hexadecimal: " + rgba);
- b = _parse_col(rgba, from + 4);
+ b = _parse_col(rgba, from + 4) / 255f;
if (b < 0)
- throw new ArgumentOutOfRangeException("Invalid color code. Blue is " + b + " but zero or greater is expected: " + rgba);
+ throw new ArgumentOutOfRangeException("Invalid color code. Blue part is not valid hexadecimal: " + rgba);
}
public static bool operator ==(Color left, Color right)
diff --git a/modules/mono/glue/cs_files/DebuggingUtils.cs b/modules/mono/glue/cs_files/DebuggingUtils.cs
new file mode 100644
index 0000000000..ffaaf00837
--- /dev/null
+++ b/modules/mono/glue/cs_files/DebuggingUtils.cs
@@ -0,0 +1,83 @@
+using System;
+using System.Diagnostics;
+using System.Reflection;
+using System.Text;
+
+namespace Godot
+{
+ internal static class DebuggingUtils
+ {
+ internal static void AppendTypeName(this StringBuilder sb, Type type)
+ {
+ if (type.IsPrimitive)
+ sb.Append(type.Name);
+ else if (type == typeof(void))
+ sb.Append("void");
+ else
+ sb.Append(type.ToString());
+
+ sb.Append(" ");
+ }
+
+ public static void GetStackFrameInfo(StackFrame frame, out string fileName, out int fileLineNumber, out string methodDecl)
+ {
+ fileName = frame.GetFileName();
+ fileLineNumber = frame.GetFileLineNumber();
+
+ MethodBase methodBase = frame.GetMethod();
+
+ if (methodBase == null)
+ {
+ methodDecl = string.Empty;
+ return;
+ }
+
+ StringBuilder sb = new StringBuilder();
+
+ if (methodBase is MethodInfo)
+ sb.AppendTypeName(((MethodInfo)methodBase).ReturnType);
+
+ sb.Append(methodBase.DeclaringType.FullName);
+ sb.Append(".");
+ sb.Append(methodBase.Name);
+
+ if (methodBase.IsGenericMethod)
+ {
+ Type[] genericParams = methodBase.GetGenericArguments();
+
+ sb.Append("<");
+
+ for (int j = 0; j < genericParams.Length; j++)
+ {
+ if (j > 0)
+ sb.Append(", ");
+
+ sb.AppendTypeName(genericParams[j]);
+ }
+
+ sb.Append(">");
+ }
+
+ sb.Append("(");
+
+ bool varArgs = (methodBase.CallingConvention & CallingConventions.VarArgs) != 0;
+
+ ParameterInfo[] parameter = methodBase.GetParameters();
+
+ for (int i = 0; i < parameter.Length; i++)
+ {
+ if (i > 0)
+ sb.Append(", ");
+
+ if (i == parameter.Length - 1 && varArgs)
+ sb.Append("params ");
+
+ sb.AppendTypeName(parameter[i].ParameterType);
+ }
+
+ sb.Append(")");
+
+ methodDecl = sb.ToString();
+ }
+ }
+}
diff --git a/modules/mono/glue/cs_files/Plane.cs b/modules/mono/glue/cs_files/Plane.cs
index 6365e71826..b347c0835a 100644
--- a/modules/mono/glue/cs_files/Plane.cs
+++ b/modules/mono/glue/cs_files/Plane.cs
@@ -91,7 +91,7 @@ namespace Godot
float dist = (normal.Dot(from) - d) / den;
- // This is a ray, before the emiting pos (from) does not exist
+ // This is a ray, before the emitting pos (from) does not exist
if (dist > Mathf.Epsilon)
return new Vector3();
diff --git a/modules/mono/glue/glue_header.h b/modules/mono/glue/glue_header.h
index 1d64fa4d72..cedc8e9992 100644
--- a/modules/mono/glue/glue_header.h
+++ b/modules/mono/glue/glue_header.h
@@ -27,6 +27,9 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
+#include "builtin_types_glue.h"
+
#include "../csharp_script.h"
#include "../mono_gd/gd_mono_class.h"
#include "../mono_gd/gd_mono_internals.h"
@@ -90,12 +93,6 @@ MonoString *godot_icall_NodePath_operator_String(NodePath *p_np) {
return GDMonoMarshal::mono_string_from_godot(p_np->operator String());
}
-MonoArray *godot_icall_String_md5_buffer(MonoString *p_str) {
- Vector<uint8_t> ret = GDMonoMarshal::mono_string_to_godot(p_str).md5_buffer();
- // TODO Check possible Array/Vector<uint8_t> problem?
- return GDMonoMarshal::Array_to_mono_array(Variant(ret));
-}
-
// -- RID --
RID *godot_icall_RID_Ctor(Object *p_from) {
@@ -114,6 +111,12 @@ void godot_icall_RID_Dtor(RID *p_ptr) {
// -- String --
+MonoArray *godot_icall_String_md5_buffer(MonoString *p_str) {
+ Vector<uint8_t> ret = GDMonoMarshal::mono_string_to_godot(p_str).md5_buffer();
+ // TODO Check possible Array/Vector<uint8_t> problem?
+ return GDMonoMarshal::Array_to_mono_array(Variant(ret));
+}
+
MonoString *godot_icall_String_md5_text(MonoString *p_str) {
String ret = GDMonoMarshal::mono_string_to_godot(p_str).md5_text();
return GDMonoMarshal::mono_string_from_godot(ret);
@@ -302,3 +305,7 @@ MonoObject *godot_icall_Godot_weakref(Object *p_obj) {
return GDMonoUtils::create_managed_for_godot_object(CACHED_CLASS(WeakRef), Reference::get_class_static(), Object::cast_to<Object>(wref.ptr()));
}
+
+void godot_register_header_icalls() {
+ godot_register_builtin_type_icalls();
+}
diff --git a/modules/mono/godotsharp_defs.h b/modules/mono/godotsharp_defs.h
index 1679eb6242..4c26c3e6bd 100644
--- a/modules/mono/godotsharp_defs.h
+++ b/modules/mono/godotsharp_defs.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GODOTSHARP_DEFS_H
#define GODOTSHARP_DEFS_H
diff --git a/modules/mono/godotsharp_dirs.cpp b/modules/mono/godotsharp_dirs.cpp
index a2965080d6..92c5cdc5c1 100644
--- a/modules/mono/godotsharp_dirs.cpp
+++ b/modules/mono/godotsharp_dirs.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "godotsharp_dirs.h"
#include "os/os.h"
diff --git a/modules/mono/godotsharp_dirs.h b/modules/mono/godotsharp_dirs.h
index 0e484fea91..e87b5a4150 100644
--- a/modules/mono/godotsharp_dirs.h
+++ b/modules/mono/godotsharp_dirs.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GODOTSHARP_DIRS_H
#define GODOTSHARP_DIRS_H
diff --git a/modules/mono/mono_gc_handle.cpp b/modules/mono/mono_gc_handle.cpp
index 5ae12f5ebf..4e82bcd03e 100644
--- a/modules/mono/mono_gc_handle.cpp
+++ b/modules/mono/mono_gc_handle.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "mono_gc_handle.h"
#include "mono_gd/gd_mono.h"
diff --git a/modules/mono/mono_gc_handle.h b/modules/mono/mono_gc_handle.h
index 565f5d4f76..9cb3ef0fbb 100644
--- a/modules/mono/mono_gc_handle.h
+++ b/modules/mono/mono_gc_handle.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef CSHARP_GC_HANDLE_H
#define CSHARP_GC_HANDLE_H
diff --git a/modules/mono/mono_gd/gd_mono.cpp b/modules/mono/mono_gd/gd_mono.cpp
index 5b65f020fc..f5febd415b 100644
--- a/modules/mono/mono_gd/gd_mono.cpp
+++ b/modules/mono/mono_gd/gd_mono.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono.h"
#include <mono/metadata/exception.h>
@@ -52,8 +53,7 @@ void gdmono_unhandled_exception_hook(MonoObject *exc, void *user_data) {
(void)user_data; // UNUSED
- ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8());
- mono_print_unhandled_exception(exc);
+ GDMonoUtils::print_unhandled_exception(exc);
abort();
}
@@ -226,7 +226,7 @@ void GDMono::initialize() {
mono_install_unhandled_exception_hook(gdmono_unhandled_exception_hook, NULL);
- OS::get_singleton()->print("Mono: ALL IS GOOD\n");
+ OS::get_singleton()->print("Mono: INITIALIZED\n");
}
#ifndef MONO_GLUE_DISABLED
@@ -696,11 +696,13 @@ bool _GodotSharp::is_domain_loaded() {
return GDMono::get_singleton()->get_scripts_domain() != NULL;
}
-#define ENQUEUE_FOR_DISPOSAL(m_queue, m_inst) \
- m_queue.push_back(m_inst); \
- if (queue_empty) { \
- queue_empty = false; \
- call_deferred("_dispose_callback"); \
+#define ENQUEUE_FOR_DISPOSAL(m_queue, m_inst) \
+ m_queue.push_back(m_inst); \
+ if (queue_empty) { \
+ queue_empty = false; \
+ if (!is_finalizing_domain()) { /* call_deferred may not be safe here */ \
+ call_deferred("_dispose_callback"); \
+ } \
}
void _GodotSharp::queue_dispose(MonoObject *p_mono_object, Object *p_object) {
diff --git a/modules/mono/mono_gd/gd_mono.h b/modules/mono/mono_gd/gd_mono.h
index c565e26de6..67251778c6 100644
--- a/modules/mono/mono_gd/gd_mono.h
+++ b/modules/mono/mono_gd/gd_mono.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONO_H
#define GD_MONO_H
@@ -112,14 +113,6 @@ public:
#endif
#endif
- enum MemberVisibility {
- PRIVATE,
- PROTECTED_AND_INTERNAL, // FAM_AND_ASSEM
- INTERNAL, // ASSEMBLY
- PROTECTED, // FAMILY
- PUBLIC
- };
-
static GDMono *get_singleton() { return singleton; }
// Do not use these, unless you know what you're doing
diff --git a/modules/mono/mono_gd/gd_mono_assembly.cpp b/modules/mono/mono_gd/gd_mono_assembly.cpp
index 7a1bf99a36..ba56ed6ed5 100644
--- a/modules/mono/mono_gd/gd_mono_assembly.cpp
+++ b/modules/mono/mono_gd/gd_mono_assembly.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_assembly.h"
#include <mono/metadata/mono-debug.h>
@@ -318,7 +319,7 @@ GDMonoClass *GDMonoAssembly::get_object_derived_class(const StringName &p_class)
void *iter = NULL;
while (true) {
- MonoClass *raw_nested = mono_class_get_nested_types(current_nested->get_raw(), &iter);
+ MonoClass *raw_nested = mono_class_get_nested_types(current_nested->get_mono_ptr(), &iter);
if (!raw_nested)
break;
diff --git a/modules/mono/mono_gd/gd_mono_assembly.h b/modules/mono/mono_gd/gd_mono_assembly.h
index 9f38202758..8e7aa701bf 100644
--- a/modules/mono/mono_gd/gd_mono_assembly.h
+++ b/modules/mono/mono_gd/gd_mono_assembly.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONO_ASSEMBLY_H
#define GD_MONO_ASSEMBLY_H
diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp
index 2bcce86d8c..b826352f02 100644
--- a/modules/mono/mono_gd/gd_mono_class.cpp
+++ b/modules/mono/mono_gd/gd_mono_class.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_class.h"
#include <mono/metadata/attrdefs.h>
@@ -35,7 +36,7 @@
MonoType *GDMonoClass::get_raw_type(GDMonoClass *p_class) {
- return mono_class_get_type(p_class->get_raw());
+ return mono_class_get_type(p_class->get_mono_ptr());
}
bool GDMonoClass::is_assignable_from(GDMonoClass *p_from) const {
@@ -74,7 +75,7 @@ Vector<MonoClassField *> GDMonoClass::get_enum_fields() {
void *iter = NULL;
MonoClassField *raw_field = NULL;
- while ((raw_field = mono_class_get_fields(get_raw(), &iter)) != NULL) {
+ while ((raw_field = mono_class_get_fields(get_mono_ptr(), &iter)) != NULL) {
uint32_t field_flags = mono_field_get_flags(raw_field);
// Enums have an instance field named value__ which holds the value of the enum.
@@ -88,11 +89,6 @@ Vector<MonoClassField *> GDMonoClass::get_enum_fields() {
}
#endif
-bool GDMonoClass::has_method(const StringName &p_name) {
-
- return get_method(p_name) != NULL;
-}
-
bool GDMonoClass::has_attribute(GDMonoClass *p_attr_class) {
#ifdef DEBUG_ENABLED
@@ -105,7 +101,7 @@ bool GDMonoClass::has_attribute(GDMonoClass *p_attr_class) {
if (!attributes)
return false;
- return mono_custom_attrs_has_attr(attributes, p_attr_class->get_raw());
+ return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr());
}
MonoObject *GDMonoClass::get_attribute(GDMonoClass *p_attr_class) {
@@ -120,14 +116,14 @@ MonoObject *GDMonoClass::get_attribute(GDMonoClass *p_attr_class) {
if (!attributes)
return NULL;
- return mono_custom_attrs_get_attr(attributes, p_attr_class->get_raw());
+ return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr());
}
void GDMonoClass::fetch_attributes() {
ERR_FAIL_COND(attributes != NULL);
- attributes = mono_custom_attrs_from_class(get_raw());
+ attributes = mono_custom_attrs_from_class(get_mono_ptr());
attrs_fetched = true;
}
@@ -140,7 +136,7 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base
void *iter = NULL;
MonoMethod *raw_method = NULL;
- while ((raw_method = mono_class_get_methods(get_raw(), &iter)) != NULL) {
+ while ((raw_method = mono_class_get_methods(get_mono_ptr(), &iter)) != NULL) {
StringName name = mono_method_get_name(raw_method);
GDMonoMethod *method = get_method(raw_method, name);
@@ -224,7 +220,7 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base
methods_fetched = true;
}
-GDMonoMethod *GDMonoClass::get_method(const StringName &p_name) {
+GDMonoMethod *GDMonoClass::get_fetched_method_unknown_params(const StringName &p_name) {
ERR_FAIL_COND_V(!methods_fetched, NULL);
@@ -238,6 +234,11 @@ GDMonoMethod *GDMonoClass::get_method(const StringName &p_name) {
return NULL;
}
+bool GDMonoClass::has_fetched_method_unknown_params(const StringName &p_name) {
+
+ return get_fetched_method_unknown_params(p_name) != NULL;
+}
+
GDMonoMethod *GDMonoClass::get_method(const StringName &p_name, int p_params_count) {
MethodKey key = MethodKey(p_name, p_params_count);
@@ -302,6 +303,8 @@ GDMonoMethod *GDMonoClass::get_method_with_desc(const String &p_description, boo
MonoMethod *method = mono_method_desc_search_in_class(desc, mono_class);
mono_method_desc_free(desc);
+ ERR_FAIL_COND_V(mono_method_get_class(method) != mono_class, NULL);
+
return get_method(method);
}
@@ -334,7 +337,7 @@ const Vector<GDMonoField *> &GDMonoClass::get_all_fields() {
void *iter = NULL;
MonoClassField *raw_field = NULL;
- while ((raw_field = mono_class_get_fields(get_raw(), &iter)) != NULL) {
+ while ((raw_field = mono_class_get_fields(mono_class, &iter)) != NULL) {
StringName name = mono_field_get_name(raw_field);
Map<StringName, GDMonoField *>::Element *match = fields.find(name);
@@ -353,6 +356,54 @@ const Vector<GDMonoField *> &GDMonoClass::get_all_fields() {
return fields_list;
}
+GDMonoProperty *GDMonoClass::get_property(const StringName &p_name) {
+
+ Map<StringName, GDMonoProperty *>::Element *result = properties.find(p_name);
+
+ if (result)
+ return result->value();
+
+ if (properties_fetched)
+ return NULL;
+
+ MonoProperty *raw_property = mono_class_get_property_from_name(mono_class, String(p_name).utf8().get_data());
+
+ if (raw_property) {
+ GDMonoProperty *property = memnew(GDMonoProperty(raw_property, this));
+ properties.insert(p_name, property);
+
+ return property;
+ }
+
+ return NULL;
+}
+
+const Vector<GDMonoProperty *> &GDMonoClass::get_all_properties() {
+
+ if (properties_fetched)
+ return properties_list;
+
+ void *iter = NULL;
+ MonoProperty *raw_property = NULL;
+ while ((raw_property = mono_class_get_properties(mono_class, &iter)) != NULL) {
+ StringName name = mono_property_get_name(raw_property);
+
+ Map<StringName, GDMonoProperty *>::Element *match = properties.find(name);
+
+ if (match) {
+ properties_list.push_back(match->get());
+ } else {
+ GDMonoProperty *property = memnew(GDMonoProperty(raw_property, this));
+ properties.insert(name, property);
+ properties_list.push_back(property);
+ }
+ }
+
+ properties_fetched = true;
+
+ return properties_list;
+}
+
GDMonoClass::GDMonoClass(const StringName &p_namespace, const StringName &p_name, MonoClass *p_class, GDMonoAssembly *p_assembly) {
namespace_name = p_namespace;
@@ -365,6 +416,7 @@ GDMonoClass::GDMonoClass(const StringName &p_namespace, const StringName &p_name
methods_fetched = false;
fields_fetched = false;
+ properties_fetched = false;
}
GDMonoClass::~GDMonoClass() {
@@ -377,6 +429,10 @@ GDMonoClass::~GDMonoClass() {
memdelete(E->value());
}
+ for (Map<StringName, GDMonoProperty *>::Element *E = properties.front(); E; E = E->next()) {
+ memdelete(E->value());
+ }
+
{
// Ugly workaround...
// We may have duplicated values, because we redirect snake_case methods to PascalCasel (only Godot API methods).
diff --git a/modules/mono/mono_gd/gd_mono_class.h b/modules/mono/mono_gd/gd_mono_class.h
index b9d34eef3a..f5895be144 100644
--- a/modules/mono/mono_gd/gd_mono_class.h
+++ b/modules/mono/mono_gd/gd_mono_class.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONO_CLASS_H
#define GD_MONO_CLASS_H
@@ -38,6 +39,7 @@
#include "gd_mono_field.h"
#include "gd_mono_header.h"
#include "gd_mono_method.h"
+#include "gd_mono_property.h"
#include "gd_mono_utils.h"
class GDMonoClass {
@@ -84,6 +86,10 @@ class GDMonoClass {
Map<StringName, GDMonoField *> fields;
Vector<GDMonoField *> fields_list;
+ bool properties_fetched;
+ Map<StringName, GDMonoProperty *> properties;
+ Vector<GDMonoProperty *> properties_list;
+
friend class GDMonoAssembly;
GDMonoClass(const StringName &p_namespace, const StringName &p_name, MonoClass *p_class, GDMonoAssembly *p_assembly);
@@ -95,7 +101,7 @@ public:
_FORCE_INLINE_ StringName get_namespace() const { return namespace_name; }
_FORCE_INLINE_ StringName get_name() const { return class_name; }
- _FORCE_INLINE_ MonoClass *get_raw() const { return mono_class; }
+ _FORCE_INLINE_ MonoClass *get_mono_ptr() const { return mono_class; }
_FORCE_INLINE_ const GDMonoAssembly *get_assembly() const { return assembly; }
String get_full_name() const;
@@ -106,7 +112,8 @@ public:
Vector<MonoClassField *> get_enum_fields();
#endif
- bool has_method(const StringName &p_name);
+ GDMonoMethod *get_fetched_method_unknown_params(const StringName &p_name);
+ bool has_fetched_method_unknown_params(const StringName &p_name);
bool has_attribute(GDMonoClass *p_attr_class);
MonoObject *get_attribute(GDMonoClass *p_attr_class);
@@ -114,8 +121,7 @@ public:
void fetch_attributes();
void fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base);
- GDMonoMethod *get_method(const StringName &p_name);
- GDMonoMethod *get_method(const StringName &p_name, int p_params_count);
+ GDMonoMethod *get_method(const StringName &p_name, int p_params_count = 0);
GDMonoMethod *get_method(MonoMethod *p_raw_method);
GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name);
GDMonoMethod *get_method(MonoMethod *p_raw_method, const StringName &p_name, int p_params_count);
@@ -124,6 +130,9 @@ public:
GDMonoField *get_field(const StringName &p_name);
const Vector<GDMonoField *> &get_all_fields();
+ GDMonoProperty *get_property(const StringName &p_name);
+ const Vector<GDMonoProperty *> &get_all_properties();
+
~GDMonoClass();
};
diff --git a/modules/mono/mono_gd/gd_mono_class_member.h b/modules/mono/mono_gd/gd_mono_class_member.h
new file mode 100644
index 0000000000..008ea0e416
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_class_member.h
@@ -0,0 +1,67 @@
+/*************************************************************************/
+/* gd_mono_class_member.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#ifndef GD_MONO_CLASS_MEMBER_H
+#define GD_MONO_CLASS_MEMBER_H
+
+#include "gd_mono_header.h"
+
+#include <mono/metadata/object.h>
+
+class GDMonoClassMember {
+public:
+ enum Visibility {
+ PRIVATE,
+ PROTECTED_AND_INTERNAL, // FAM_AND_ASSEM
+ INTERNAL, // ASSEMBLY
+ PROTECTED, // FAMILY
+ PUBLIC
+ };
+
+ enum MemberType {
+ MEMBER_TYPE_FIELD,
+ MEMBER_TYPE_PROPERTY,
+ MEMBER_TYPE_METHOD
+ };
+
+ virtual ~GDMonoClassMember() {}
+
+ virtual MemberType get_member_type() = 0;
+
+ virtual StringName get_name() = 0;
+
+ virtual bool is_static() = 0;
+
+ virtual Visibility get_visibility() = 0;
+
+ virtual bool has_attribute(GDMonoClass *p_attr_class) = 0;
+ virtual MonoObject *get_attribute(GDMonoClass *p_attr_class) = 0;
+};
+
+#endif // GD_MONO_CLASS_MEMBER_H
diff --git a/modules/mono/mono_gd/gd_mono_field.cpp b/modules/mono/mono_gd/gd_mono_field.cpp
index 133cfc9145..3b91777ed4 100644
--- a/modules/mono/mono_gd/gd_mono_field.cpp
+++ b/modules/mono/mono_gd/gd_mono_field.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_field.h"
#include <mono/metadata/attrdefs.h>
@@ -38,7 +39,7 @@ void GDMonoField::set_value_raw(MonoObject *p_object, void *p_ptr) {
mono_field_set_value(p_object, mono_field, &p_ptr);
}
-void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) {
+void GDMonoField::set_value_from_variant(MonoObject *p_object, const Variant &p_value) {
#define SET_FROM_STRUCT_AND_BREAK(m_type) \
{ \
const m_type &val = p_value.operator ::m_type(); \
@@ -138,7 +139,7 @@ void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) {
if (tclass == CACHED_CLASS(Plane))
SET_FROM_STRUCT_AND_BREAK(Plane);
- if (mono_class_is_enum(tclass->get_raw()))
+ if (mono_class_is_enum(tclass->get_mono_ptr()))
SET_FROM_PRIMITIVE(signed int);
ERR_EXPLAIN(String() + "Attempted to set the value of a field of unmarshallable type: " + tclass->get_name());
@@ -264,7 +265,7 @@ void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) {
} break;
case MONO_TYPE_GENERICINST: {
- if (CACHED_RAW_MONO_CLASS(Dictionary) == type.type_class->get_raw()) {
+ if (CACHED_RAW_MONO_CLASS(Dictionary) == type.type_class->get_mono_ptr()) {
MonoObject *managed = GDMonoMarshal::Dictionary_to_mono_object(p_value.operator Dictionary());
mono_field_set_value(p_object, mono_field, managed);
break;
@@ -280,6 +281,10 @@ void GDMonoField::set_value(MonoObject *p_object, const Variant &p_value) {
#undef SET_FROM_PRIMITIVE
}
+MonoObject *GDMonoField::get_value(MonoObject *p_object) {
+ return mono_field_get_value_object(mono_domain_get(), mono_field, p_object);
+}
+
bool GDMonoField::get_bool_value(MonoObject *p_object) {
return (bool)GDMonoMarshal::unbox<MonoBoolean>(get_value(p_object));
}
@@ -302,7 +307,7 @@ bool GDMonoField::has_attribute(GDMonoClass *p_attr_class) {
if (!attributes)
return false;
- return mono_custom_attrs_has_attr(attributes, p_attr_class->get_raw());
+ return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr());
}
MonoObject *GDMonoField::get_attribute(GDMonoClass *p_attr_class) {
@@ -314,12 +319,12 @@ MonoObject *GDMonoField::get_attribute(GDMonoClass *p_attr_class) {
if (!attributes)
return NULL;
- return mono_custom_attrs_get_attr(attributes, p_attr_class->get_raw());
+ return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr());
}
void GDMonoField::fetch_attributes() {
ERR_FAIL_COND(attributes != NULL);
- attributes = mono_custom_attrs_from_field(owner->get_raw(), get_raw());
+ attributes = mono_custom_attrs_from_field(owner->get_mono_ptr(), mono_field);
attrs_fetched = true;
}
@@ -327,26 +332,26 @@ bool GDMonoField::is_static() {
return mono_field_get_flags(mono_field) & MONO_FIELD_ATTR_STATIC;
}
-GDMono::MemberVisibility GDMonoField::get_visibility() {
+GDMonoClassMember::Visibility GDMonoField::get_visibility() {
switch (mono_field_get_flags(mono_field) & MONO_FIELD_ATTR_FIELD_ACCESS_MASK) {
case MONO_FIELD_ATTR_PRIVATE:
- return GDMono::PRIVATE;
+ return GDMonoClassMember::PRIVATE;
case MONO_FIELD_ATTR_FAM_AND_ASSEM:
- return GDMono::PROTECTED_AND_INTERNAL;
+ return GDMonoClassMember::PROTECTED_AND_INTERNAL;
case MONO_FIELD_ATTR_ASSEMBLY:
- return GDMono::INTERNAL;
+ return GDMonoClassMember::INTERNAL;
case MONO_FIELD_ATTR_FAMILY:
- return GDMono::PROTECTED;
+ return GDMonoClassMember::PROTECTED;
case MONO_FIELD_ATTR_PUBLIC:
- return GDMono::PUBLIC;
+ return GDMonoClassMember::PUBLIC;
default:
- ERR_FAIL_V(GDMono::PRIVATE);
+ ERR_FAIL_V(GDMonoClassMember::PRIVATE);
}
}
-GDMonoField::GDMonoField(MonoClassField *p_raw_field, GDMonoClass *p_owner) {
+GDMonoField::GDMonoField(MonoClassField *p_mono_field, GDMonoClass *p_owner) {
owner = p_owner;
- mono_field = p_raw_field;
+ mono_field = p_mono_field;
name = mono_field_get_name(mono_field);
MonoType *field_type = mono_field_get_type(mono_field);
type.type_encoding = mono_type_get_type(field_type);
diff --git a/modules/mono/mono_gd/gd_mono_field.h b/modules/mono/mono_gd/gd_mono_field.h
index a5559df059..a6b368c4d6 100644
--- a/modules/mono/mono_gd/gd_mono_field.h
+++ b/modules/mono/mono_gd/gd_mono_field.h
@@ -27,47 +27,49 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GDMONOFIELD_H
#define GDMONOFIELD_H
#include "gd_mono.h"
+#include "gd_mono_class_member.h"
#include "gd_mono_header.h"
-class GDMonoField {
+class GDMonoField : public GDMonoClassMember {
+
GDMonoClass *owner;
MonoClassField *mono_field;
- String name;
+ StringName name;
ManagedType type;
bool attrs_fetched;
MonoCustomAttrInfo *attributes;
public:
- _FORCE_INLINE_ String get_name() const { return name; }
- _FORCE_INLINE_ ManagedType get_type() const { return type; }
+ virtual MemberType get_member_type() { return MEMBER_TYPE_FIELD; }
- _FORCE_INLINE_ MonoClassField *get_raw() const { return mono_field; }
+ virtual StringName get_name() { return name; }
+
+ virtual bool is_static();
+ virtual Visibility get_visibility();
+
+ virtual bool has_attribute(GDMonoClass *p_attr_class);
+ virtual MonoObject *get_attribute(GDMonoClass *p_attr_class);
+ void fetch_attributes();
+
+ _FORCE_INLINE_ ManagedType get_type() const { return type; }
void set_value_raw(MonoObject *p_object, void *p_ptr);
- void set_value(MonoObject *p_object, const Variant &p_value);
+ void set_value_from_variant(MonoObject *p_object, const Variant &p_value);
- _FORCE_INLINE_ MonoObject *get_value(MonoObject *p_object) {
- return mono_field_get_value_object(mono_domain_get(), mono_field, p_object);
- }
+ MonoObject *get_value(MonoObject *p_object);
bool get_bool_value(MonoObject *p_object);
int get_int_value(MonoObject *p_object);
String get_string_value(MonoObject *p_object);
- bool has_attribute(GDMonoClass *p_attr_class);
- MonoObject *get_attribute(GDMonoClass *p_attr_class);
- void fetch_attributes();
-
- bool is_static();
- GDMono::MemberVisibility get_visibility();
-
- GDMonoField(MonoClassField *p_raw_field, GDMonoClass *p_owner);
+ GDMonoField(MonoClassField *p_mono_field, GDMonoClass *p_owner);
~GDMonoField();
};
diff --git a/modules/mono/mono_gd/gd_mono_header.h b/modules/mono/mono_gd/gd_mono_header.h
index a749aa8768..2b5110f0b9 100644
--- a/modules/mono/mono_gd/gd_mono_header.h
+++ b/modules/mono/mono_gd/gd_mono_header.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONO_HEADER_H
#define GD_MONO_HEADER_H
@@ -34,8 +35,10 @@
class GDMonoAssembly;
class GDMonoClass;
-class GDMonoMethod;
+class GDMonoClassMember;
class GDMonoField;
+class GDMonoProperty;
+class GDMonoMethod;
struct ManagedType {
int type_encoding;
diff --git a/modules/mono/mono_gd/gd_mono_internals.cpp b/modules/mono/mono_gd/gd_mono_internals.cpp
index 95d15c3581..a1a79f957f 100644
--- a/modules/mono/mono_gd/gd_mono_internals.cpp
+++ b/modules/mono/mono_gd/gd_mono_internals.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* godotsharp_internals.cpp */
+/* gd_mono_internals.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_internals.h"
#include "../csharp_script.h"
diff --git a/modules/mono/mono_gd/gd_mono_internals.h b/modules/mono/mono_gd/gd_mono_internals.h
index 91f6fcbbc7..abec65e7d4 100644
--- a/modules/mono/mono_gd/gd_mono_internals.h
+++ b/modules/mono/mono_gd/gd_mono_internals.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* godotsharp_internals.h */
+/* gd_mono_internals.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONO_INTERNALS_H
#define GD_MONO_INTERNALS_H
diff --git a/modules/mono/mono_gd/gd_mono_log.cpp b/modules/mono/mono_gd/gd_mono_log.cpp
index f954530552..eabea8dc3c 100644
--- a/modules/mono/mono_gd/gd_mono_log.cpp
+++ b/modules/mono/mono_gd/gd_mono_log.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_log.h"
#include <mono/utils/mono-logger.h>
diff --git a/modules/mono/mono_gd/gd_mono_log.h b/modules/mono/mono_gd/gd_mono_log.h
index 4ed5f2a255..a7e374858c 100644
--- a/modules/mono/mono_gd/gd_mono_log.h
+++ b/modules/mono/mono_gd/gd_mono_log.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONO_LOG_H
#define GD_MONO_LOG_H
diff --git a/modules/mono/mono_gd/gd_mono_marshal.cpp b/modules/mono/mono_gd/gd_mono_marshal.cpp
index 48d08b159c..aa1a8e39c7 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.cpp
+++ b/modules/mono/mono_gd/gd_mono_marshal.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_marshal.h"
#include "gd_mono.h"
@@ -113,7 +114,7 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type) {
if (tclass == CACHED_CLASS(Plane))
return Variant::PLANE;
- if (mono_class_is_enum(tclass->get_raw()))
+ if (mono_class_is_enum(tclass->get_mono_ptr()))
return Variant::INT;
} break;
@@ -164,7 +165,7 @@ Variant::Type managed_to_variant_type(const ManagedType &p_type) {
} break;
case MONO_TYPE_GENERICINST: {
- if (CACHED_RAW_MONO_CLASS(Dictionary) == p_type.type_class->get_raw()) {
+ if (CACHED_RAW_MONO_CLASS(Dictionary) == p_type.type_class->get_mono_ptr()) {
return Variant::DICTIONARY;
}
} break;
@@ -306,9 +307,9 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
if (tclass == CACHED_CLASS(Plane))
RETURN_BOXED_STRUCT(Plane, p_var);
- if (mono_class_is_enum(tclass->get_raw())) {
+ if (mono_class_is_enum(tclass->get_mono_ptr())) {
int val = p_var->operator signed int();
- return BOX_ENUM(tclass->get_raw(), val);
+ return BOX_ENUM(tclass->get_mono_ptr(), val);
}
} break;
@@ -432,7 +433,7 @@ MonoObject *variant_to_mono_object(const Variant *p_var, const ManagedType &p_ty
}
break;
case MONO_TYPE_GENERICINST: {
- if (CACHED_RAW_MONO_CLASS(Dictionary) == p_type.type_class->get_raw()) {
+ if (CACHED_RAW_MONO_CLASS(Dictionary) == p_type.type_class->get_mono_ptr()) {
return Dictionary_to_mono_object(p_var->operator Dictionary());
}
} break;
@@ -458,11 +459,7 @@ Variant mono_object_to_variant(MonoObject *p_obj) {
type.type_encoding = mono_type_get_type(raw_type);
type.type_class = tclass;
- return mono_object_to_variant(p_obj, type);
-}
-
-Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) {
- switch (p_type.type_encoding) {
+ switch (type.type_encoding) {
case MONO_TYPE_BOOLEAN:
return (bool)unbox<MonoBoolean>(p_obj);
@@ -496,7 +493,7 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) {
} break;
case MONO_TYPE_VALUETYPE: {
- GDMonoClass *tclass = p_type.type_class;
+ GDMonoClass *tclass = type.type_class;
if (tclass == CACHED_CLASS(Vector2))
RETURN_UNBOXED_STRUCT(Vector2, p_obj);
@@ -528,13 +525,13 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) {
if (tclass == CACHED_CLASS(Plane))
RETURN_UNBOXED_STRUCT(Plane, p_obj);
- if (mono_class_is_enum(tclass->get_raw()))
+ if (mono_class_is_enum(tclass->get_mono_ptr()))
return unbox<int32_t>(p_obj);
} break;
case MONO_TYPE_ARRAY:
case MONO_TYPE_SZARRAY: {
- MonoArrayType *array_type = mono_type_get_array_type(GDMonoClass::get_raw_type(p_type.type_class));
+ MonoArrayType *array_type = mono_type_get_array_type(GDMonoClass::get_raw_type(type.type_class));
if (array_type->eklass == CACHED_CLASS_RAW(MonoObject))
return mono_array_to_Array((MonoArray *)p_obj);
@@ -565,7 +562,7 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) {
} break;
case MONO_TYPE_CLASS: {
- GDMonoClass *type_class = p_type.type_class;
+ GDMonoClass *type_class = type.type_class;
// GodotObject
if (CACHED_CLASS(GodotObject)->is_assignable_from(type_class)) {
@@ -585,14 +582,14 @@ Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type) {
} break;
case MONO_TYPE_GENERICINST: {
- if (CACHED_RAW_MONO_CLASS(Dictionary) == p_type.type_class->get_raw()) {
+ if (CACHED_RAW_MONO_CLASS(Dictionary) == type.type_class->get_mono_ptr()) {
return mono_object_to_Dictionary(p_obj);
}
} break;
}
ERR_EXPLAIN(String() + "Attempted to convert an unmarshallable managed type to Variant. Name: \'" +
- p_type.type_class->get_name() + "\' Encoding: " + itos(p_type.type_encoding));
+ type.type_class->get_name() + "\' Encoding: " + itos(type.type_encoding));
ERR_FAIL_V(Variant());
}
diff --git a/modules/mono/mono_gd/gd_mono_marshal.h b/modules/mono/mono_gd/gd_mono_marshal.h
index 0570415575..6572408ab5 100644
--- a/modules/mono/mono_gd/gd_mono_marshal.h
+++ b/modules/mono/mono_gd/gd_mono_marshal.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GDMONOMARSHAL_H
#define GDMONOMARSHAL_H
@@ -101,7 +102,6 @@ _FORCE_INLINE_ MonoObject *variant_to_mono_object(Variant p_var) {
}
Variant mono_object_to_variant(MonoObject *p_obj);
-Variant mono_object_to_variant(MonoObject *p_obj, const ManagedType &p_type);
// Array
diff --git a/modules/mono/mono_gd/gd_mono_method.cpp b/modules/mono/mono_gd/gd_mono_method.cpp
index 01afd1e51e..1f8e9a1926 100644
--- a/modules/mono/mono_gd/gd_mono_method.cpp
+++ b/modules/mono/mono_gd/gd_mono_method.cpp
@@ -27,11 +27,14 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_method.h"
#include "gd_mono_class.h"
#include "gd_mono_marshal.h"
+#include <mono/metadata/attrdefs.h>
+
void GDMonoMethod::_update_signature() {
// Apparently MonoMethodSignature needs not to be freed.
// mono_method_signature caches the result, we don't need to cache it ourselves.
@@ -41,7 +44,6 @@ void GDMonoMethod::_update_signature() {
}
void GDMonoMethod::_update_signature(MonoMethodSignature *p_method_sig) {
- is_instance = mono_signature_is_instance(p_method_sig);
params_count = mono_signature_get_param_count(p_method_sig);
MonoType *ret_type = mono_signature_get_return_type(p_method_sig);
@@ -61,15 +63,34 @@ void GDMonoMethod::_update_signature(MonoMethodSignature *p_method_sig) {
param_type.type_encoding = mono_type_get_type(param_raw_type);
- if (param_type.type_encoding != MONO_TYPE_VOID) {
- MonoClass *param_type_class = mono_class_from_mono_type(param_raw_type);
- param_type.type_class = GDMono::get_singleton()->get_class(param_type_class);
- }
+ MonoClass *param_type_class = mono_class_from_mono_type(param_raw_type);
+ param_type.type_class = GDMono::get_singleton()->get_class(param_type_class);
param_types.push_back(param_type);
}
}
+bool GDMonoMethod::is_static() {
+ return mono_method_get_flags(mono_method, NULL) & MONO_METHOD_ATTR_STATIC;
+}
+
+GDMonoClassMember::Visibility GDMonoMethod::get_visibility() {
+ switch (mono_method_get_flags(mono_method, NULL) & MONO_METHOD_ATTR_ACCESS_MASK) {
+ case MONO_METHOD_ATTR_PRIVATE:
+ return GDMonoClassMember::PRIVATE;
+ case MONO_METHOD_ATTR_FAM_AND_ASSEM:
+ return GDMonoClassMember::PROTECTED_AND_INTERNAL;
+ case MONO_METHOD_ATTR_ASSEM:
+ return GDMonoClassMember::INTERNAL;
+ case MONO_METHOD_ATTR_FAMILY:
+ return GDMonoClassMember::PROTECTED;
+ case MONO_METHOD_ATTR_PUBLIC:
+ return GDMonoClassMember::PUBLIC;
+ default:
+ ERR_FAIL_V(GDMonoClassMember::PRIVATE);
+ }
+}
+
void *GDMonoMethod::get_thunk() {
return mono_method_get_unmanaged_thunk(mono_method);
}
@@ -87,11 +108,11 @@ MonoObject *GDMonoMethod::invoke(MonoObject *p_object, const Variant **p_params,
MonoObject *ret = mono_runtime_invoke_array(mono_method, p_object, params, &exc);
if (exc) {
+ ret = NULL;
if (r_exc) {
*r_exc = exc;
} else {
- ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8());
- mono_print_unhandled_exception(exc);
+ GDMonoUtils::print_unhandled_exception(exc);
}
}
@@ -104,8 +125,7 @@ MonoObject *GDMonoMethod::invoke(MonoObject *p_object, const Variant **p_params,
if (r_exc) {
*r_exc = exc;
} else {
- ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8());
- mono_print_unhandled_exception(exc);
+ GDMonoUtils::print_unhandled_exception(exc);
}
}
@@ -123,11 +143,11 @@ MonoObject *GDMonoMethod::invoke_raw(MonoObject *p_object, void **p_params, Mono
MonoObject *ret = mono_runtime_invoke(mono_method, p_object, p_params, &exc);
if (exc) {
+ ret = NULL;
if (r_exc) {
*r_exc = exc;
} else {
- ERR_PRINT(GDMonoUtils::get_exception_name_and_message(exc).utf8());
- mono_print_unhandled_exception(exc);
+ GDMonoUtils::print_unhandled_exception(exc);
}
}
@@ -143,7 +163,7 @@ bool GDMonoMethod::has_attribute(GDMonoClass *p_attr_class) {
if (!attributes)
return false;
- return mono_custom_attrs_has_attr(attributes, p_attr_class->get_raw());
+ return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr());
}
MonoObject *GDMonoMethod::get_attribute(GDMonoClass *p_attr_class) {
@@ -155,7 +175,7 @@ MonoObject *GDMonoMethod::get_attribute(GDMonoClass *p_attr_class) {
if (!attributes)
return NULL;
- return mono_custom_attrs_get_attr(attributes, p_attr_class->get_raw());
+ return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr());
}
void GDMonoMethod::fetch_attributes() {
diff --git a/modules/mono/mono_gd/gd_mono_method.h b/modules/mono/mono_gd/gd_mono_method.h
index f1f6e51d45..14df8dcfb4 100644
--- a/modules/mono/mono_gd/gd_mono_method.h
+++ b/modules/mono/mono_gd/gd_mono_method.h
@@ -27,17 +27,18 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONO_METHOD_H
#define GD_MONO_METHOD_H
#include "gd_mono.h"
+#include "gd_mono_class_member.h"
#include "gd_mono_header.h"
-class GDMonoMethod {
+class GDMonoMethod : public GDMonoClassMember {
StringName name;
- bool is_instance;
int params_count;
ManagedType return_type;
Vector<ManagedType> param_types;
@@ -53,9 +54,18 @@ class GDMonoMethod {
MonoMethod *mono_method;
public:
- _FORCE_INLINE_ StringName get_name() { return name; }
+ virtual MemberType get_member_type() { return MEMBER_TYPE_METHOD; }
+
+ virtual StringName get_name() { return name; }
+
+ virtual bool is_static();
+
+ virtual Visibility get_visibility();
+
+ virtual bool has_attribute(GDMonoClass *p_attr_class);
+ virtual MonoObject *get_attribute(GDMonoClass *p_attr_class);
+ virtual void fetch_attributes();
- _FORCE_INLINE_ bool is_static() { return !is_instance; }
_FORCE_INLINE_ int get_parameters_count() { return params_count; }
_FORCE_INLINE_ ManagedType get_return_type() { return return_type; }
@@ -65,10 +75,6 @@ public:
MonoObject *invoke(MonoObject *p_object, MonoObject **r_exc = NULL);
MonoObject *invoke_raw(MonoObject *p_object, void **p_params, MonoObject **r_exc = NULL);
- bool has_attribute(GDMonoClass *p_attr_class);
- MonoObject *get_attribute(GDMonoClass *p_attr_class);
- void fetch_attributes();
-
String get_full_name(bool p_signature = false) const;
String get_full_name_no_class() const;
String get_ret_type_full_name() const;
diff --git a/modules/mono/mono_gd/gd_mono_property.cpp b/modules/mono/mono_gd/gd_mono_property.cpp
new file mode 100644
index 0000000000..0fe527b199
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_property.cpp
@@ -0,0 +1,199 @@
+/*************************************************************************/
+/* gd_mono_property.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#include "gd_mono_property.h"
+
+#include "gd_mono_class.h"
+#include "gd_mono_marshal.h"
+
+#include <mono/metadata/attrdefs.h>
+
+GDMonoProperty::GDMonoProperty(MonoProperty *p_mono_property, GDMonoClass *p_owner) {
+ owner = p_owner;
+ mono_property = p_mono_property;
+ name = mono_property_get_name(mono_property);
+
+ MonoMethod *prop_method = mono_property_get_get_method(mono_property);
+
+ if (prop_method) {
+ MonoMethodSignature *getter_sig = mono_method_signature(prop_method);
+
+ MonoType *ret_type = mono_signature_get_return_type(getter_sig);
+
+ type.type_encoding = mono_type_get_type(ret_type);
+ MonoClass *ret_type_class = mono_class_from_mono_type(ret_type);
+ type.type_class = GDMono::get_singleton()->get_class(ret_type_class);
+ } else {
+ prop_method = mono_property_get_set_method(mono_property);
+
+ MonoMethodSignature *setter_sig = mono_method_signature(prop_method);
+
+ void *iter = NULL;
+ MonoType *param_raw_type = mono_signature_get_params(setter_sig, &iter);
+
+ type.type_encoding = mono_type_get_type(param_raw_type);
+ MonoClass *param_type_class = mono_class_from_mono_type(param_raw_type);
+ type.type_class = GDMono::get_singleton()->get_class(param_type_class);
+ }
+
+ attrs_fetched = false;
+ attributes = NULL;
+}
+
+GDMonoProperty::~GDMonoProperty() {
+ if (attributes) {
+ mono_custom_attrs_free(attributes);
+ }
+}
+
+bool GDMonoProperty::is_static() {
+ MonoMethod *prop_method = mono_property_get_get_method(mono_property);
+ if (prop_method == NULL)
+ prop_method = mono_property_get_set_method(mono_property);
+ return mono_method_get_flags(prop_method, NULL) & MONO_METHOD_ATTR_STATIC;
+}
+
+GDMonoClassMember::Visibility GDMonoProperty::get_visibility() {
+ MonoMethod *prop_method = mono_property_get_get_method(mono_property);
+ if (prop_method == NULL)
+ prop_method = mono_property_get_set_method(mono_property);
+
+ switch (mono_method_get_flags(prop_method, NULL) & MONO_METHOD_ATTR_ACCESS_MASK) {
+ case MONO_METHOD_ATTR_PRIVATE:
+ return GDMonoClassMember::PRIVATE;
+ case MONO_METHOD_ATTR_FAM_AND_ASSEM:
+ return GDMonoClassMember::PROTECTED_AND_INTERNAL;
+ case MONO_METHOD_ATTR_ASSEM:
+ return GDMonoClassMember::INTERNAL;
+ case MONO_METHOD_ATTR_FAMILY:
+ return GDMonoClassMember::PROTECTED;
+ case MONO_METHOD_ATTR_PUBLIC:
+ return GDMonoClassMember::PUBLIC;
+ default:
+ ERR_FAIL_V(GDMonoClassMember::PRIVATE);
+ }
+}
+
+bool GDMonoProperty::has_attribute(GDMonoClass *p_attr_class) {
+ ERR_FAIL_NULL_V(p_attr_class, false);
+
+ if (!attrs_fetched)
+ fetch_attributes();
+
+ if (!attributes)
+ return false;
+
+ return mono_custom_attrs_has_attr(attributes, p_attr_class->get_mono_ptr());
+}
+
+MonoObject *GDMonoProperty::get_attribute(GDMonoClass *p_attr_class) {
+ ERR_FAIL_NULL_V(p_attr_class, NULL);
+
+ if (!attrs_fetched)
+ fetch_attributes();
+
+ if (!attributes)
+ return NULL;
+
+ return mono_custom_attrs_get_attr(attributes, p_attr_class->get_mono_ptr());
+}
+
+void GDMonoProperty::fetch_attributes() {
+ ERR_FAIL_COND(attributes != NULL);
+ attributes = mono_custom_attrs_from_property(owner->get_mono_ptr(), mono_property);
+ attrs_fetched = true;
+}
+
+bool GDMonoProperty::has_getter() {
+ return mono_property_get_get_method(mono_property) != NULL;
+}
+
+bool GDMonoProperty::has_setter() {
+ return mono_property_get_set_method(mono_property) != NULL;
+}
+
+void GDMonoProperty::set_value(MonoObject *p_object, MonoObject *p_value, MonoObject **r_exc) {
+ MonoMethod *prop_method = mono_property_get_set_method(mono_property);
+
+ MonoArray *params = mono_array_new(mono_domain_get(), CACHED_CLASS_RAW(MonoObject), 1);
+ mono_array_set(params, MonoObject *, 0, p_value);
+
+ MonoObject *exc = NULL;
+ mono_runtime_invoke_array(prop_method, p_object, params, &exc);
+
+ if (exc) {
+ if (r_exc) {
+ *r_exc = exc;
+ } else {
+ GDMonoUtils::print_unhandled_exception(exc);
+ }
+ }
+}
+
+void GDMonoProperty::set_value(MonoObject *p_object, void **p_params, MonoObject **r_exc) {
+ MonoObject *exc = NULL;
+ mono_property_set_value(mono_property, p_object, p_params, &exc);
+
+ if (exc) {
+ if (r_exc) {
+ *r_exc = exc;
+ } else {
+ GDMonoUtils::print_unhandled_exception(exc);
+ }
+ }
+}
+
+MonoObject *GDMonoProperty::get_value(MonoObject *p_object, MonoObject **r_exc) {
+ MonoObject *exc = NULL;
+ MonoObject *ret = mono_property_get_value(mono_property, p_object, NULL, &exc);
+
+ if (exc) {
+ ret = NULL;
+ if (r_exc) {
+ *r_exc = exc;
+ } else {
+ GDMonoUtils::print_unhandled_exception(exc);
+ }
+ }
+
+ return ret;
+}
+
+bool GDMonoProperty::get_bool_value(MonoObject *p_object) {
+ return (bool)GDMonoMarshal::unbox<MonoBoolean>(get_value(p_object));
+}
+
+int GDMonoProperty::get_int_value(MonoObject *p_object) {
+ return GDMonoMarshal::unbox<int32_t>(get_value(p_object));
+}
+
+String GDMonoProperty::get_string_value(MonoObject *p_object) {
+ MonoObject *val = get_value(p_object);
+ return GDMonoMarshal::mono_string_to_godot((MonoString *)val);
+}
diff --git a/modules/mono/mono_gd/gd_mono_property.h b/modules/mono/mono_gd/gd_mono_property.h
new file mode 100644
index 0000000000..2a0065e850
--- /dev/null
+++ b/modules/mono/mono_gd/gd_mono_property.h
@@ -0,0 +1,77 @@
+/*************************************************************************/
+/* gd_mono_property.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2018 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2018 Godot Engine contributors (cf. AUTHORS.md) */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+#ifndef GD_MONO_PROPERTY_H
+#define GD_MONO_PROPERTY_H
+
+#include "gd_mono.h"
+#include "gd_mono_class_member.h"
+#include "gd_mono_header.h"
+
+class GDMonoProperty : public GDMonoClassMember {
+
+ GDMonoClass *owner;
+ MonoProperty *mono_property;
+
+ StringName name;
+ ManagedType type;
+
+ bool attrs_fetched;
+ MonoCustomAttrInfo *attributes;
+
+public:
+ virtual MemberType get_member_type() { return MEMBER_TYPE_PROPERTY; }
+
+ virtual StringName get_name() { return name; }
+
+ virtual bool is_static();
+ virtual Visibility get_visibility();
+
+ virtual bool has_attribute(GDMonoClass *p_attr_class);
+ virtual MonoObject *get_attribute(GDMonoClass *p_attr_class);
+ void fetch_attributes();
+
+ bool has_getter();
+ bool has_setter();
+
+ _FORCE_INLINE_ ManagedType get_type() const { return type; }
+
+ void set_value(MonoObject *p_object, MonoObject *p_value, MonoObject **r_exc = NULL);
+ void set_value(MonoObject *p_object, void **p_params, MonoObject **r_exc = NULL);
+ MonoObject *get_value(MonoObject *p_object, MonoObject **r_exc = NULL);
+
+ bool get_bool_value(MonoObject *p_object);
+ int get_int_value(MonoObject *p_object);
+ String get_string_value(MonoObject *p_object);
+
+ GDMonoProperty(MonoProperty *p_mono_property, GDMonoClass *p_owner);
+ ~GDMonoProperty();
+};
+
+#endif // GD_MONO_PROPERTY_H
diff --git a/modules/mono/mono_gd/gd_mono_utils.cpp b/modules/mono/mono_gd/gd_mono_utils.cpp
index 03f3053372..a2f0819a72 100644
--- a/modules/mono/mono_gd/gd_mono_utils.cpp
+++ b/modules/mono/mono_gd/gd_mono_utils.cpp
@@ -27,9 +27,11 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "gd_mono_utils.h"
#include "os/dir_access.h"
+#include "os/os.h"
#include "project_settings.h"
#include "reference.h"
@@ -42,16 +44,20 @@ namespace GDMonoUtils {
MonoCache mono_cache;
-#define CACHE_AND_CHECK(m_var, m_val) \
- { \
- m_var = m_val; \
- if (!m_var) ERR_PRINT("Mono Cache: Member " #m_var " is null. This is really bad!"); \
+#define CACHE_AND_CHECK(m_var, m_val) \
+ { \
+ m_var = m_val; \
+ if (!m_var) { \
+ ERR_EXPLAIN("Mono Cache: Member " #m_var " is null"); \
+ ERR_FAIL(); \
+ } \
}
#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)
+#define CACHE_METHOD_AND_CHECK(m_class, m_method, m_val) CACHE_AND_CHECK(GDMonoUtils::mono_cache.method_##m_class##_##m_method, m_val)
#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)
void MonoCache::clear_members() {
@@ -71,6 +77,13 @@ void MonoCache::clear_members() {
class_String = NULL;
class_IntPtr = NULL;
+#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
+
rawclass_Dictionary = NULL;
class_Vector2 = NULL;
@@ -93,6 +106,11 @@ void MonoCache::clear_members() {
class_WeakRef = NULL;
class_MarshalUtils = NULL;
+#ifdef DEBUG_ENABLED
+ class_DebuggingUtils = NULL;
+ methodthunk_DebuggingUtils_GetStackFrameInfo = NULL;
+#endif
+
class_ExportAttribute = NULL;
field_ExportAttribute_hint = NULL;
field_ExportAttribute_hintString = NULL;
@@ -118,6 +136,12 @@ void MonoCache::clear_members() {
task_scheduler_handle = Ref<MonoGCHandle>();
}
+void MonoCache::cleanup() {
+
+ corlib_cache_updated = false;
+ godot_api_cache_updated = false;
+}
+
#define GODOT_API_CLASS(m_class) (GDMono::get_singleton()->get_api_assembly()->get_class(BINDINGS_NAMESPACE, #m_class))
void update_corlib_cache() {
@@ -136,6 +160,15 @@ void update_corlib_cache() {
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()));
+
+#ifdef DEBUG_ENABLED
+ CACHE_CLASS_AND_CHECK(System_Diagnostics_StackTrace, GDMono::get_singleton()->get_corlib_assembly()->get_class("System.Diagnostics", "StackTrace"));
+ CACHE_METHOD_THUNK_AND_CHECK(System_Diagnostics_StackTrace, GetFrames, (StackTrace_GetFrames)CACHED_CLASS(System_Diagnostics_StackTrace)->get_method("GetFrames")->get_thunk());
+ 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
+
+ mono_cache.corlib_cache_updated = true;
}
void update_godot_api_cache() {
@@ -151,7 +184,7 @@ void update_godot_api_cache() {
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));
- CACHE_CLASS_AND_CHECK(RID, GODOT_API_CLASS(NodePath));
+ CACHE_CLASS_AND_CHECK(RID, GODOT_API_CLASS(RID));
CACHE_CLASS_AND_CHECK(GodotObject, GODOT_API_CLASS(Object));
CACHE_CLASS_AND_CHECK(GodotReference, GODOT_API_CLASS(Reference));
CACHE_CLASS_AND_CHECK(Node, GODOT_API_CLASS(Node));
@@ -160,6 +193,10 @@ void update_godot_api_cache() {
CACHE_CLASS_AND_CHECK(WeakRef, GODOT_API_CLASS(WeakRef));
CACHE_CLASS_AND_CHECK(MarshalUtils, GODOT_API_CLASS(MarshalUtils));
+#ifdef DEBUG_ENABLED
+ CACHE_CLASS_AND_CHECK(DebuggingUtils, GODOT_API_CLASS(DebuggingUtils));
+#endif
+
// Attributes
CACHE_CLASS_AND_CHECK(ExportAttribute, GODOT_API_CLASS(ExportAttribute));
CACHE_FIELD_AND_CHECK(ExportAttribute, hint, CACHED_CLASS(ExportAttribute)->get_field("hint"));
@@ -182,6 +219,10 @@ void update_godot_api_cache() {
CACHE_METHOD_THUNK_AND_CHECK(SignalAwaiter, FailureCallback, (SignalAwaiter_FailureCallback)GODOT_API_CLASS(SignalAwaiter)->get_method("FailureCallback", 0)->get_thunk());
CACHE_METHOD_THUNK_AND_CHECK(GodotTaskScheduler, Activate, (GodotTaskScheduler_Activate)GODOT_API_CLASS(GodotTaskScheduler)->get_method("Activate", 0)->get_thunk());
+#ifdef DEBUG_ENABLED
+ CACHE_METHOD_THUNK_AND_CHECK(DebuggingUtils, GetStackFrameInfo, (DebugUtils_StackFrameInfo)GODOT_API_CLASS(DebuggingUtils)->get_method("GetStackFrameInfo", 4)->get_thunk());
+#endif
+
{
/*
* TODO Right now we only support Dictionary<object, object>.
@@ -198,9 +239,11 @@ void update_godot_api_cache() {
CACHE_RAW_MONO_CLASS_AND_CHECK(Dictionary, mono_class_from_mono_type(dict_type));
}
- MonoObject *task_scheduler = mono_object_new(SCRIPTS_DOMAIN, GODOT_API_CLASS(GodotTaskScheduler)->get_raw());
+ MonoObject *task_scheduler = mono_object_new(SCRIPTS_DOMAIN, GODOT_API_CLASS(GodotTaskScheduler)->get_mono_ptr());
mono_runtime_object_init(task_scheduler);
mono_cache.task_scheduler_handle = MonoGCHandle::create_strong(task_scheduler);
+
+ mono_cache.corlib_cache_updated = true;
}
void clear_cache() {
@@ -298,7 +341,7 @@ MonoObject *create_managed_for_godot_object(GDMonoClass *p_class, const StringNa
ERR_FAIL_V(NULL);
}
- MonoObject *mono_object = mono_object_new(SCRIPTS_DOMAIN, p_class->get_raw());
+ MonoObject *mono_object = mono_object_new(SCRIPTS_DOMAIN, p_class->get_mono_ptr());
ERR_FAIL_NULL_V(mono_object, NULL);
CACHED_FIELD(GodotObject, ptr)->set_value_raw(mono_object, p_object);
@@ -364,4 +407,51 @@ String get_exception_name_and_message(MonoObject *p_ex) {
return res;
}
+
+void print_unhandled_exception(MonoObject *p_exc) {
+ print_unhandled_exception(p_exc, false);
+}
+
+void print_unhandled_exception(MonoObject *p_exc, bool p_recursion_caution) {
+ mono_print_unhandled_exception(p_exc);
+#ifdef DEBUG_ENABLED
+ if (!ScriptDebugger::get_singleton())
+ return;
+
+ 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 };
+
+ MonoObject *unexpected_exc = NULL;
+ CACHED_METHOD(System_Diagnostics_StackTrace, ctor_Exception_bool)->invoke_raw(stack_trace, ctor_args, &unexpected_exc);
+
+ if (unexpected_exc != NULL) {
+ mono_print_unhandled_exception(unexpected_exc);
+
+ if (p_recursion_caution) {
+ // Called from CSharpLanguage::get_current_stack_info,
+ // so printing an error here could result in endless recursion
+ OS::get_singleton()->printerr("Mono: Method GDMonoUtils::print_unhandled_exception failed");
+ return;
+ } else {
+ ERR_FAIL();
+ }
+ }
+
+ Vector<ScriptLanguage::StackInfo> si;
+ if (stack_trace != NULL && !p_recursion_caution)
+ si = CSharpLanguage::get_singleton()->stack_trace_get_info(stack_trace);
+
+ 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";
+ String exc_msg = GDMonoUtils::get_exception_name_and_message(p_exc);
+
+ ScriptDebugger::get_singleton()->send_error(func, file, line, error_msg, exc_msg, ERR_HANDLER_ERROR, si);
+#endif
+}
+
} // namespace GDMonoUtils
diff --git a/modules/mono/mono_gd/gd_mono_utils.h b/modules/mono/mono_gd/gd_mono_utils.h
index 62d31f78fb..259da46c31 100644
--- a/modules/mono/mono_gd/gd_mono_utils.h
+++ b/modules/mono/mono_gd/gd_mono_utils.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef GD_MONOUTILS_H
#define GD_MONOUTILS_H
@@ -42,16 +43,13 @@ namespace GDMonoUtils {
typedef MonoObject *(*MarshalUtils_DictToArrays)(MonoObject *, MonoArray **, MonoArray **, MonoObject **);
typedef MonoObject *(*MarshalUtils_ArraysToDict)(MonoArray *, MonoArray *, MonoObject **);
-typedef MonoObject *(*SignalAwaiter_SignalCallback)(MonoObject *, MonoArray **, MonoObject **);
+typedef MonoObject *(*SignalAwaiter_SignalCallback)(MonoObject *, MonoArray *, MonoObject **);
typedef MonoObject *(*SignalAwaiter_FailureCallback)(MonoObject *, MonoObject **);
typedef MonoObject *(*GodotTaskScheduler_Activate)(MonoObject *, MonoObject **);
+typedef MonoArray *(*StackTrace_GetFrames)(MonoObject *, MonoObject **);
+typedef void (*DebugUtils_StackFrameInfo)(MonoObject *, MonoString **, int *, MonoString **, MonoObject **);
struct MonoCache {
- // Format for cached classes in the Godot namespace: class_<Class>
- // Macro: CACHED_CLASS(<Class>)
-
- // Format for cached classes in a different namespace: class_<Namespace>_<Class>
- // Macro: CACHED_NS_CLASS(<Namespace>, <Class>)
// -----------------------------------------------
// corlib classes
@@ -72,6 +70,13 @@ struct MonoCache {
GDMonoClass *class_String;
GDMonoClass *class_IntPtr;
+#ifdef DEBUG_ENABLED
+ GDMonoClass *class_System_Diagnostics_StackTrace;
+ StackTrace_GetFrames methodthunk_System_Diagnostics_StackTrace_GetFrames;
+ GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_bool;
+ GDMonoMethod *method_System_Diagnostics_StackTrace_ctor_Exception_bool;
+#endif
+
MonoClass *rawclass_Dictionary;
// -----------------------------------------------
@@ -95,6 +100,11 @@ struct MonoCache {
GDMonoClass *class_WeakRef;
GDMonoClass *class_MarshalUtils;
+#ifdef DEBUG_ENABLED
+ GDMonoClass *class_DebuggingUtils;
+ DebugUtils_StackFrameInfo methodthunk_DebuggingUtils_GetStackFrameInfo;
+#endif
+
GDMonoClass *class_ExportAttribute;
GDMonoField *field_ExportAttribute_hint;
GDMonoField *field_ExportAttribute_hintString;
@@ -119,10 +129,16 @@ struct MonoCache {
Ref<MonoGCHandle> task_scheduler_handle;
+ bool corlib_cache_updated;
+ bool godot_api_cache_updated;
+
void clear_members();
- void cleanup() {}
+ void cleanup();
MonoCache() {
+ corlib_cache_updated = false;
+ godot_api_cache_updated = false;
+
clear_members();
}
};
@@ -166,15 +182,18 @@ MonoDomain *create_domain(const String &p_friendly_name);
String get_exception_name_and_message(MonoObject *p_ex);
+void print_unhandled_exception(MonoObject *p_exc);
+void print_unhandled_exception(MonoObject *p_exc, bool p_recursion_caution);
+
} // namespace GDMonoUtils
#define NATIVE_GDMONOCLASS_NAME(m_class) (GDMonoMarshal::mono_string_to_godot((MonoString *)m_class->get_field(BINDINGS_NATIVE_NAME_FIELD)->get_value(NULL)))
#define CACHED_CLASS(m_class) (GDMonoUtils::mono_cache.class_##m_class)
-#define CACHED_CLASS_RAW(m_class) (GDMonoUtils::mono_cache.class_##m_class->get_raw())
-#define CACHED_NS_CLASS(m_ns, m_class) (GDMonoUtils::mono_cache.class_##m_ns##_##m_class)
+#define CACHED_CLASS_RAW(m_class) (GDMonoUtils::mono_cache.class_##m_class->get_mono_ptr())
#define CACHED_RAW_MONO_CLASS(m_class) (GDMonoUtils::mono_cache.rawclass_##m_class)
#define CACHED_FIELD(m_class, m_field) (GDMonoUtils::mono_cache.field_##m_class##_##m_field)
+#define CACHED_METHOD(m_class, m_method) (GDMonoUtils::mono_cache.method_##m_class##_##m_method)
#define CACHED_METHOD_THUNK(m_class, m_method) (GDMonoUtils::mono_cache.methodthunk_##m_class##_##m_method)
#ifdef REAL_T_IS_DOUBLE
diff --git a/modules/mono/register_types.cpp b/modules/mono/register_types.cpp
index 9bc384063d..4410996546 100644
--- a/modules/mono/register_types.cpp
+++ b/modules/mono/register_types.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "register_types.h"
#include "engine.h"
diff --git a/modules/mono/register_types.h b/modules/mono/register_types.h
index d4f052b793..ab8a7d6463 100644
--- a/modules/mono/register_types.h
+++ b/modules/mono/register_types.h
@@ -27,5 +27,6 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
void register_mono_types();
void unregister_mono_types();
diff --git a/modules/mono/signal_awaiter_utils.cpp b/modules/mono/signal_awaiter_utils.cpp
index bad75224dc..b9d8520ac9 100644
--- a/modules/mono/signal_awaiter_utils.cpp
+++ b/modules/mono/signal_awaiter_utils.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "signal_awaiter_utils.h"
#include "csharp_script.h"
@@ -101,7 +102,7 @@ Variant SignalAwaiterHandle::_signal_callback(const Variant **p_args, int p_argc
GDMonoUtils::SignalAwaiter_SignalCallback thunk = CACHED_METHOD_THUNK(SignalAwaiter, SignalCallback);
MonoObject *ex = NULL;
- thunk(get_target(), &signal_args, &ex);
+ thunk(get_target(), signal_args, &ex);
if (ex) {
mono_print_unhandled_exception(ex);
diff --git a/modules/mono/signal_awaiter_utils.h b/modules/mono/signal_awaiter_utils.h
index 97cf4238da..a6a205ff8d 100644
--- a/modules/mono/signal_awaiter_utils.h
+++ b/modules/mono/signal_awaiter_utils.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef SIGNAL_AWAITER_UTILS_H
#define SIGNAL_AWAITER_UTILS_H
diff --git a/modules/mono/utils/mono_reg_utils.cpp b/modules/mono/utils/mono_reg_utils.cpp
index 8d91e16c5c..9bb8da8ac0 100644
--- a/modules/mono/utils/mono_reg_utils.cpp
+++ b/modules/mono/utils/mono_reg_utils.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "mono_reg_utils.h"
#ifdef WINDOWS_ENABLED
diff --git a/modules/mono/utils/mono_reg_utils.h b/modules/mono/utils/mono_reg_utils.h
index 80270ad794..edf31f5a07 100644
--- a/modules/mono/utils/mono_reg_utils.h
+++ b/modules/mono/utils/mono_reg_utils.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef MONO_REG_UTILS_H
#define MONO_REG_UTILS_H
diff --git a/modules/mono/utils/path_utils.cpp b/modules/mono/utils/path_utils.cpp
index dfbb1b9ba4..4b77aeb54e 100644
--- a/modules/mono/utils/path_utils.cpp
+++ b/modules/mono/utils/path_utils.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "path_utils.h"
#include "os/dir_access.h"
diff --git a/modules/mono/utils/path_utils.h b/modules/mono/utils/path_utils.h
index 4e8d8f2815..184cacfac7 100644
--- a/modules/mono/utils/path_utils.h
+++ b/modules/mono/utils/path_utils.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef PATH_UTILS_H
#define PATH_UTILS_H
diff --git a/modules/mono/utils/string_utils.cpp b/modules/mono/utils/string_utils.cpp
index 4bea504d28..8691932f9a 100644
--- a/modules/mono/utils/string_utils.cpp
+++ b/modules/mono/utils/string_utils.cpp
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#include "string_utils.h"
namespace {
diff --git a/modules/mono/utils/string_utils.h b/modules/mono/utils/string_utils.h
index b02abc77be..5dddaee6e8 100644
--- a/modules/mono/utils/string_utils.h
+++ b/modules/mono/utils/string_utils.h
@@ -27,6 +27,7 @@
/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
+
#ifndef STRING_FORMAT_H
#define STRING_FORMAT_H