mirror of
https://github.com/godotengine/godot.git
synced 2025-02-18 16:50:48 +00:00
Improve C# method listing
- implement CSharpInstance::get_method_list
- loop through parent classes in CSharpInstance::get_method_list and CSharpScript::get_script_method_list (#46408)
(cherry picked from commit 19f25b6847
)
This commit is contained in:
parent
d1a4cb2bea
commit
e2b71de38b
@ -1630,6 +1630,28 @@ Variant::Type CSharpInstance::get_property_type(const StringName &p_name, bool *
|
||||
return Variant::NIL;
|
||||
}
|
||||
|
||||
void CSharpInstance::get_method_list(List<MethodInfo> *p_list) const {
|
||||
if (!script->is_valid() || !script->script_class)
|
||||
return;
|
||||
|
||||
GD_MONO_SCOPE_THREAD_ATTACH;
|
||||
|
||||
// TODO: We're filtering out constructors but there may be other methods unsuitable for explicit calls.
|
||||
GDMonoClass *top = script->script_class;
|
||||
|
||||
while (top && top != script->native) {
|
||||
const Vector<GDMonoMethod *> &methods = top->get_all_methods();
|
||||
for (int i = 0; i < methods.size(); ++i) {
|
||||
MethodInfo minfo = methods[i]->get_method_info();
|
||||
if (minfo.name != CACHED_STRING_NAME(dotctor)) {
|
||||
p_list->push_back(minfo);
|
||||
}
|
||||
}
|
||||
|
||||
top = top->get_parent_class();
|
||||
}
|
||||
}
|
||||
|
||||
bool CSharpInstance::has_method(const StringName &p_method) const {
|
||||
if (!script.is_valid())
|
||||
return false;
|
||||
@ -3034,10 +3056,19 @@ void CSharpScript::get_script_method_list(List<MethodInfo> *p_list) const {
|
||||
|
||||
GD_MONO_SCOPE_THREAD_ATTACH;
|
||||
|
||||
// TODO: Filter out things unsuitable for explicit calls, like constructors.
|
||||
const Vector<GDMonoMethod *> &methods = script_class->get_all_methods();
|
||||
for (int i = 0; i < methods.size(); ++i) {
|
||||
p_list->push_back(methods[i]->get_method_info());
|
||||
// TODO: We're filtering out constructors but there may be other methods unsuitable for explicit calls.
|
||||
GDMonoClass *top = script_class;
|
||||
|
||||
while (top && top != native) {
|
||||
const Vector<GDMonoMethod *> &methods = top->get_all_methods();
|
||||
for (int i = 0; i < methods.size(); ++i) {
|
||||
MethodInfo minfo = methods[i]->get_method_info();
|
||||
if (minfo.name != CACHED_STRING_NAME(dotctor)) {
|
||||
p_list->push_back(methods[i]->get_method_info());
|
||||
}
|
||||
}
|
||||
|
||||
top = top->get_parent_class();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -255,7 +255,7 @@ public:
|
||||
virtual void get_property_list(List<PropertyInfo> *p_properties) const;
|
||||
virtual Variant::Type get_property_type(const StringName &p_name, bool *r_is_valid) const;
|
||||
|
||||
/* TODO */ virtual void get_method_list(List<MethodInfo> *p_list) const {}
|
||||
virtual void get_method_list(List<MethodInfo> *p_list) const;
|
||||
virtual bool has_method(const StringName &p_method) const;
|
||||
virtual Variant call(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error);
|
||||
virtual void call_multilevel(const StringName &p_method, const Variant **p_args, int p_argcount);
|
||||
|
Loading…
Reference in New Issue
Block a user