[Mono-list] Embedding mono

Jonathan Pryor jonpryor@vt.edu
Fri, 18 Jun 2004 22:34:27 -0400


On Fri, 2004-06-18 at 16:08, Joe Ante wrote:
> > It should be possible to load assemblies on demand.
> Ok so how exactly does this work?
> 
> Say I have two .cs files. One calls a function in the other .cs file.
> Obviously just compiling the two .cs files seperately in two different
> .dll's gives me a compile error for the .cs file that tries to use the other
> .cs file.

Circular dependencies are notoriously complicated in a statically typed
environment.  The simple answer would be to put both .cs files into the
same assembly, but this isn't apparently what you want to do.

Paolo could answer this better, but I would imagine that assemblies are
demand-paged from disk -- only the parts of the assembly that you
actually use are loaded, so I don't see any reason to not put everything
into the same assembly.

> So is there some kind of import/include mechanism?

I'm not sure what you mean by import/include, but I imagine it's related
to your questions below, so hopefully my answers below will help.

> The problem I am trying to solve is:
> 
> We have a game creation tool which includes a text editor to change scripts
> (At the moment using python). Python has a import function, which is
> necessary if you want to use a class that is defined in another script file.
> We intercepted the import function and returned it the correct python script
> and built a dependency tree. When the user saves a pythonscript we recompile
> all pythonscripts that import the script the user has changed.
> It is very important for us that saving/recompiling is immediate (less than
> half a second).
> 
> So whats the best way to do that?

It sounds like you want a highly dynamic environment, in which existing
code can be changed at runtime, with older code silently invoking newer
code.

I don't believe it's possible, or at least easily possible, to do this
in C#.  This sounds more like something System.Reflection.Emit and a
custom compiler would be useful for.  That way, you could ensure fast
compile time, and you could come up with a custom way for pre-existing
code to invoke newer code without requiring recompilation (interfaces
might be good for this).

I would suggest looking into IronPython, which is a Python
implementation for .NET.  This may be an easier migration path for you,
assuming you can actually get your hands on it (it's currently a
"unreleased research prototype", but the author might be willing to
help; I have no idea...).

 - Jon