Hello,

maybe a Ruby guru can give a solution to my problem?
I started using Ruby this month (but I read all
information I could find) and do not know how to solve
the problem without changing the Ruby source code.

My goal is to enrich a Windows GUI application by an embedded
ruby interpreter. The Ruby dll should be loaded at runtime,
because the application must not depend on the availability
of a certain ruby version. The user can choose which Ruby dll
he/she wants to use, and even switch from one version to another.

At first, I noticed that there is a ruby_init() which among
other things saves the stack base address for later usage
by ruby's garbage collection. So it was not possible to call
the Ruby interpreter's rb_eval_string() from a different
stack context, for example from different threads. Doing so
would raise fatal runtime errors as my experiments soon showed.
I might disable garbage collection permanently, but obviously
this is not a good solution.

It is not possible to restart the ruby interpreter with a clean
state without restarting the whole Windows application. This is
caused by the fact that ruby_init() only saves the stack base 
address at the first call, so a restart (which uses a different
stack context in our application) leads to desaster.

If it were possible to unload the Ruby dll completely, this
would solve my problem because then I could load it again and
ruby_init() calculates a new stack base. But this works only
for very simple Ruby scripts. A script which uses require()
loads additional shared libraries (dlls) which are never released.
The Ruby dll won't unload with FreeLibrary() after a successful
require() statement.

So what can I do???

Thanks for your comments.

Stefan