[Mono-list] Re: [Mono-devel-list] Technical questions

Paolo Molaro lupus@ximian.com
Wed, 20 Aug 2003 15:25:39 +0200


On 08/19/03 Jonathan Pryor wrote:
> So, when you need to invoke a virtual function, you get the virtual
> function table, get the index for the function to call, and invoke it.
> 
> 	// just to convey the basic idea...
> 	MonoObject *o = get_my_object(...);
> 	void** params = get_my_method_params (...);
> 	int idx = get_method_index (...);
> 	MonoMethod *m = o->vtable->klass->vtable[idx];
> 	MonoObject* exception = NULL;
> 	mono_runtime_invoke (m, o, params, &exception);
> 	// ...
> 
> The big questions are:
>  1. How is the the index found/generated?

It's generated in mono_class_setup_vtable().

>  2. How is the MonoMethod *really* found.  I suppose it could just be a 

You shouldn't bother with that stuff: to invoke a method you eventually
need to call mono_runtime_invoke(). Now, mono_runtime_invoke()
is basically the equivalent of the call IL opcode. To do a virtual call
(a callvirt) you need a base method and you'll call:

	method = mono_object_get_virtual_method (this, basemethod);
	mono_runtime_invoke (method, this, ...);

You can look at mono_object_get_virtual_method() for the implementation
details.

lupus

-- 
-----------------------------------------------------------------
lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better