[Mono-list] mono -> libmono

Paolo Molaro lupus@ximian.com
Mon, 25 Feb 2002 16:27:51 +0100


On 02/24/02 Jeff Dubrule wrote:
> Has any work been done on encapsulating mono into a library, and
> providing an API so that other programs can use it internally?

Yes, some work has been done wrt an API to invoke arbitrary methods:
check mono_runtime_invoke () in reflection.c and how it's currently used
there and how it's actually implemented in the interp. The jit doesn't
support it yet, though.

> I'm interested in using mono to replace a VM in an existing program
> which uses its own compiler/bytecode/vm system to run code in its own
> language.  I'd like to do this by taking the existing compiler, and
> rewriting the code-generator portion to produce CIL bytecodes, then
> use mono to execute them.
> 
> It would be most convenient for me to be able to write, say:
> 
> mono_init();
> mono_add_class("foo");
> MonoCode * f = mono_compile(chunk_of_cil_bytecode);
> mono_add_class_method("foo", "bar", f);
> mono_call_class_method("foo", "bar");

You'll be able to do something like:

mono_init();
image = mono_load_assembly ("myplugin");
MonoClass *klass = mono_class_from_name (image, "namespace", "class");
MonoMethod *method = mono_get_method (klass, "methodname");
mono_runtime_invoke (method, NULL, args);
...

The actual compilation of "myplugin", needs to be a different step.

lupus

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