> Phlip wrote:

This code embeds Ruby, executes a string found in 'source', and fetches any
error message:

>     rb_gv_set("$errorLineNumber", Qnil);
> ...
>
>     VALUE value  = rb_str_new2( source );
>     rb_gv_set("$evalMe", value);
>
>     rb_eval_string_protect(
>             "begin\n"
>             "  $errorLineNumber = nil\n"
>             "  eval($evalMe, nil, 'eval', 1)\n"
>             "rescue\n"
>             "  $errorLineNumber = $@[0].slice(5..100).to_i()\n"
>             "  p $!\n"
>             "  p $@\n"
>             "  raise\n"
>             "end\n"
>             , &state);
>
>     if (state)  return state;
> ...
>     VALUE errorLineNumber = rb_gv_get("$errorLineNumber");
>
>     if (errorLineNumber != Qnil)  //  else it's in a library or something
> hard
>         {
>         int lineNo = NUM2INT(errorLineNumber);

Next problem: 'source' may contain free-form Ruby code, entered by a user.
If the user creates a variable 'foo', executes the code, erases 'foo', and
executes again, 'foo' still exists on the heap.

I want an error message if 'foo' no longer exists, from the user's point of
view. How do I reset Ruby back to the state before the eval() call? I tried
passing eval() a Proc.new{}, and I tried terminal functions like
ruby_prog_init(), ruby_finalize(), and ruby_cleanup(). They seem to destroy
too much.

So, how to clean up a local stack?

-- 
  Phlip
  http://industrialxp.org/community/bin/view/Main/TestFirstUserInterfaces