summaryrefslogtreecommitdiff
path: root/modules/mono/mono_gd/gd_mono_class.cpp
diff options
context:
space:
mode:
authorBen Rog-Wilhelm <zorba-githubdesktop20180420@pavlovian.net>2018-11-01 08:35:16 -0700
committerBen Rog-Wilhelm <zorba-git20110501@pavlovian.net>2018-12-07 23:54:40 -0800
commitf13f2d512f0439a29804182cee756dce62add857 (patch)
tree3eeb1fb32881c29ca3c6930c6073ba8ac9f57b8c /modules/mono/mono_gd/gd_mono_class.cpp
parent41d1dba35fc851258d5aabad819d09f6a43e324c (diff)
Implement CSharpScript::get_script_method_list and related functionality.
Diffstat (limited to 'modules/mono/mono_gd/gd_mono_class.cpp')
-rw-r--r--modules/mono/mono_gd/gd_mono_class.cpp27
1 files changed, 27 insertions, 0 deletions
diff --git a/modules/mono/mono_gd/gd_mono_class.cpp b/modules/mono/mono_gd/gd_mono_class.cpp
index 4e515cde28..400735bb20 100644
--- a/modules/mono/mono_gd/gd_mono_class.cpp
+++ b/modules/mono/mono_gd/gd_mono_class.cpp
@@ -139,6 +139,20 @@ void GDMonoClass::fetch_attributes() {
attrs_fetched = true;
}
+void GDMonoClass::fetch_method_list() {
+
+ if (method_list_fetched)
+ return;
+
+ void *iter = NULL;
+ MonoMethod *raw_method = NULL;
+ while ((raw_method = mono_class_get_methods(get_mono_ptr(), &iter)) != NULL) {
+ method_list.push_back(memnew(GDMonoMethod(mono_method_get_name(raw_method), raw_method)));
+ }
+
+ method_list_fetched = true;
+}
+
void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base) {
CRASH_COND(!CACHED_CLASS(GodotObject)->is_assignable_from(this));
@@ -151,6 +165,7 @@ void GDMonoClass::fetch_methods_with_godot_api_checks(GDMonoClass *p_native_base
while ((raw_method = mono_class_get_methods(get_mono_ptr(), &iter)) != NULL) {
StringName name = mono_method_get_name(raw_method);
+ // get_method implicitly fetches methods and adds them to this->methods
GDMonoMethod *method = get_method(raw_method, name);
ERR_CONTINUE(!method);
@@ -449,6 +464,13 @@ const Vector<GDMonoClass *> &GDMonoClass::get_all_delegates() {
return delegates_list;
}
+const Vector<GDMonoMethod *> &GDMonoClass::get_all_methods() {
+ if (!method_list_fetched)
+ fetch_method_list();
+
+ return method_list;
+}
+
GDMonoClass::GDMonoClass(const StringName &p_namespace, const StringName &p_name, MonoClass *p_class, GDMonoAssembly *p_assembly) {
namespace_name = p_namespace;
@@ -460,6 +482,7 @@ GDMonoClass::GDMonoClass(const StringName &p_namespace, const StringName &p_name
attributes = NULL;
methods_fetched = false;
+ method_list_fetched = false;
fields_fetched = false;
properties_fetched = false;
delegates_fetched = false;
@@ -512,4 +535,8 @@ GDMonoClass::~GDMonoClass() {
methods.clear();
}
+
+ for (int i = 0; i < method_list.size(); ++i) {
+ memdelete(method_list[i]);
+ }
}