[prev in list] [next in list] [prev in thread] [next in thread]
List: ruby-talk
Subject: How to clean out my stack
From: "Phlip" <phlip_cpp () yahoo ! com>
Date: 2004-09-24 18:10:03
Message-ID: 7oZ4d.12653$x35.2783 () newssvr31 ! news ! prodigy ! com
[Download RAW message or body]
> 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
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic