diff options
| author | Paul Joannon | 2018-01-18 23:27:43 +0100 |
|---|---|---|
| committer | Paul Joannon | 2018-02-17 19:37:02 +0100 |
| commit | cfbd7fd21e6630cc513ac3a36849c0f796d142c3 (patch) | |
| tree | 60d5f142ec6c1a989f26223d16ce2a327e016641 /modules/mono/csharp_script.cpp | |
| parent | efd52cd1725145dc9c8038477dbe133b23868e99 (diff) | |
| download | godot-cfbd7fd21e6630cc513ac3a36849c0f796d142c3.tar.gz godot-cfbd7fd21e6630cc513ac3a36849c0f796d142c3.tar.zst godot-cfbd7fd21e6630cc513ac3a36849c0f796d142c3.zip | |
Diffstat (limited to 'modules/mono/csharp_script.cpp')
| -rw-r--r-- | modules/mono/csharp_script.cpp | 68 |
1 files changed, 63 insertions, 5 deletions
diff --git a/modules/mono/csharp_script.cpp b/modules/mono/csharp_script.cpp index 609cb1c01..fb4513657 100644 --- a/modules/mono/csharp_script.cpp +++ b/modules/mono/csharp_script.cpp @@ -1566,13 +1566,13 @@ bool CSharpScript::_update_signals() { while (top && top != native) { const Vector<GDMonoClass *> &delegates = top->get_all_delegates(); - for (int i = delegates.size() - 1; i >= 0; i--) { - GDMonoClass *delegate = delegates[i]; + for (int i = delegates.size() - 1; i >= 0; --i) { + Vector<Argument> parameters; - if (delegate->has_attribute(CACHED_CLASS(SignalAttribute))) { - StringName name = delegate->get_name(); + GDMonoClass *delegate = delegates[i]; - _signals[name] = Vector<StringName>(); // TODO Retrieve arguments + if (_get_signal(top, delegate, parameters)) { + _signals[delegate->get_name()] = parameters; } } @@ -1585,6 +1585,41 @@ bool CSharpScript::_update_signals() { return false; } +bool CSharpScript::_get_signal(GDMonoClass *p_class, GDMonoClass *p_delegate, Vector<Argument> ¶ms) { + if (p_delegate->has_attribute(CACHED_CLASS(SignalAttribute))) { + MonoType *raw_type = GDMonoClass::get_raw_type(p_delegate); + + if (mono_type_get_type(raw_type) == MONO_TYPE_CLASS) { + // Arguments are accessibles as arguments of .Invoke method + GDMonoMethod *invoke = p_delegate->get_method("Invoke", -1); + + Vector<StringName> names; + Vector<ManagedType> types; + invoke->get_parameter_names(names); + invoke->get_parameter_types(types); + + if (names.size() == types.size()) { + for (int i = 0; i < names.size(); ++i) { + Argument arg; + arg.name = names[i]; + arg.type = GDMonoMarshal::managed_to_variant_type(types[i]); + + if (arg.type == Variant::NIL) { + ERR_PRINTS("Unknown type of signal parameter: " + arg.name + " in " + p_class->get_full_name()); + return false; + } + + params.push_back(arg); + } + + return true; + } + } + } + + return false; +} + #ifdef TOOLS_ENABLED bool CSharpScript::_get_member_export(GDMonoClass *p_class, GDMonoClassMember *p_member, PropertyInfo &r_prop_info, bool &r_exported) { @@ -1913,6 +1948,8 @@ ScriptInstance *CSharpScript::instance_create(Object *p_this) { #endif } + update_signals(); + if (native) { String native_name = native->get_name(); if (!ClassDB::is_parent_class(p_this->get_class_name(), native_name)) { @@ -2076,6 +2113,27 @@ void CSharpScript::update_exports() { #endif } +bool CSharpScript::has_script_signal(const StringName &p_signal) const { + if (_signals.has(p_signal)) + return true; + + return false; +} + +void CSharpScript::get_script_signal_list(List<MethodInfo> *r_signals) const { + for (const Map<StringName, Vector<Argument> >::Element *E = _signals.front(); E; E = E->next()) { + MethodInfo mi; + + mi.name = E->key(); + for (int i = 0; i < E->get().size(); i++) { + PropertyInfo arg; + arg.name = E->get()[i].name; + mi.arguments.push_back(arg); + } + r_signals->push_back(mi); + } +} + void CSharpScript::update_signals() { #ifdef TOOLS_ENABLED _update_signals(); |
