[Mono-dev] interacting with method signatures from C (embedded)

Miguel de Icaza miguel at xamarin.com
Thu Oct 27 21:56:24 EDT 2011


Let me suggest a simpler solution.

You write your FindMethod routine in C#.   Then you invoke that well-known
method from C to do the lookup for you.

Miguel

On Thu, Oct 27, 2011 at 7:23 PM, Jonathan Shore <jonathan.shore at gmail.com>wrote:

> I want to call arbitrary methods on C# / mono classes from a scripting
> language (with C as the intermediate interface between the two).   The
> method names and signatures are not known up-front, rather the scripting
> language -> C -> mono, C layer must translate calls in the scripting
> language to:
>
>    1. locate the type (ok, this is straightforward)
>    2. locate the method (not straightforward, see below)
>    3. call the method (straightforward)
>
> Locating a method with overloading seems to present an issue in that the
> public C interface does not expose sufficient access to the MonoType* and
> MonoClass* structures.   For instance, asssuming I have a function like this
> that I want to implement:
>
>
>   MonoMethod* find_method (
>     MonoDomain* domain,
>     MonoClass* type,
>     const char* name,
>     int nargs,
>     MonoClass** types)
>
>
> I can iterate over the memebers with mono_signature_get_params(), however,
> this returns a MonoType* struct reference.  I cannot examine the "type"
> field of this struct as is not seen to be a complete structure without
> including the <mono/metadata/*-internals.h> files.
>
> I am aware of the "debug-helpers" interface which allows for the search of
> a class and method signature using a string.  This interface is oriented
> towards use cases where the method one is trying to locate is fixed.  The
> construction of the string signature is expensive.  Additionally in scanning
> methods, each method matching a name is rendered as a MonoMethodDesc,
> creating strings for the classname, namespace, and parameters.  This seems
> like a lot of overhead.
>
> Ignoring the extra work / overhead in the search, assuming one has both
> primitive and object based types,* how does one create an appropriate
> parameter description string for a MonoObject**?   There is logic in
> debug-helpers.c to generate a description string from MonoType, but I do not
> see a public function for this.
>
> The lowest overhead approach would be to have access to the MonoType* and
> MonoClass* structures and be able to iterate over the parameters,
> determining whether the type enum and object name (where applicable) are
> equal.
>
> Question:  what is the best approach to locating a method given the name of
> the method and an array of MonoClass* for the parameters?   I cannot
> directly access the structures and I have not determined a way to render the
> appropriate type string for a non-primitive class.
>
> Here is a stackoverflow I posted on this:
> http://stackoverflow.com/questions/7921337/how-to-use-monotype-in-context-of-evaluating-method-signatures
>
> Thanks
>
> Jonathan
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20111027/c4bc6d95/attachment.html 


More information about the Mono-devel-list mailing list