Clear ScriptEngine Global Variables

Hi,

Is there anyway to clear all global variables from the IronRuby script
engine?

For example if I define a variable in a script and execute it:

$myVar = “Hello”

And then execute another script in a new scriptscope but with the same
ScriptEngine instance and use:

global_variables.each do |var|
print("#{var} = #{eval(’$’ + var)}")
end

Then the myVar variable from the first instance will be listed.

Thanks,

Aaron

if (Runtime.Globals.ContainsVariable(className))
Runtime.Globals.RemoveVariable(className);


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Ivan Porto carrero wrote:

if (Runtime.Globals.ContainsVariable(className))
Runtime.Globals.RemoveVariable(className);

What if i don’t know classname though?

My application is operating in a shared environment where a large number
of users are each executing their own custom scripts.

Thanks,

Aaron

Do you want to do it from ruby or from C#?

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Is that thread-safe? I’d be worried about deleting entries from a
collection I’m iterating through without knowing the implementation.


Chuck Durfee
Lead Software Architect, CentreSuite
TSYS iSolutions, Golden
Email [email protected]

Ivan Porto C. [email protected]
Sent by: [email protected]
09/30/2009 07:56 AM
Please respond to
[email protected]

To
[email protected]
cc

Subject
Re: [Ironruby-core] Clear ScriptEngine Global Variables

if (Runtime.Globals.ContainsVariable(className))
Runtime.Globals.RemoveVariable(className);


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Wed, Sep 30, 2009 at 3:43 PM, Aaron C. [email protected]
wrote:
Hi,

Is there anyway to clear all global variables from the IronRuby script
engine?

For example if I define a variable in a script and execute it:

$myVar = “Hello”

And then execute another script in a new scriptscope but with the same
ScriptEngine instance and use:

global_variables.each do |var|
print(“#{var} = #{eval(‘$’ + var)}”)
end

Then the myVar variable from the first instance will be listed.

Thanks,

Aaron

Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Ironruby-core mailing list
[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


The information contained in this communication (including any
attachments hereto) is confidential and is intended solely for the
personal and confidential use of the individual or entity to whom
it is addressed. If the reader of this message is not the intended
recipient or an agent responsible for delivering it to the intended
recipient, you are hereby notified that you have received this
communication in error and that any review, dissemination, copying,
or unauthorized use of this information, or the taking of any
action in reliance on the contents of this information is strictly
prohibited. If you have received this communication in error,
please notify us immediately by e-mail, and delete the original
message. Thank you

Ivan Porto carrero wrote:

Do you want to do it from ruby or from C#?

From C#.

Runtime.Globals actually don’t contain Ruby global variables ($xxx).
IronRuby publishes global modules defined by a script to this scope.

IronRuby 0.9.1.0 on .NET 2.0.50727.4918
Copyright (c) Microsoft Corporation. All rights reserved.

class C
… end
=> nil
module D
… end
=> nil
IronRuby.globals.methods(false)
=> [‘c’, ‘d’]
IronRuby.globals.C
=> C
IronRuby.globals.D
=> D

IronRuby.globals is a singleton method that returns the DLR Scope object
corresponding to Runtime.Globals.
True Ruby global variables ($ prefixed variables) are listed by
global_variables Ruby method:

global_variables
=> [“~”, “&”, “+”, “`”, “'”, “_”, “0”, “!”, “@”, “*”, “/”, “,”, “;”,
“\”, “<”, “>”, “"”, “:”, “.”, “?”, “PROGRAM_NAME”
, “stdin”, “stdout”, “defout”, “stderr”, “LOADED_FEATURES”, “LOAD_PATH”,
“-I”, “-O”, “-F”, “FILENAME”, “VERBOSE”, “-v”,
“-w”, “DEBUG”, “-d”, “KCODE”, “-K”, “SAFE”, “$”]

Tomas

From: [email protected]
[mailto:[email protected]] On Behalf Of
[email protected]
Sent: Wednesday, September 30, 2009 8:59 AM
To: [email protected]
Cc: [email protected]; [email protected]
Subject: Re: [Ironruby-core] Clear ScriptEngine Global Variables

Is that thread-safe? I’d be worried about deleting entries from a
collection I’m iterating through without knowing the implementation.


Chuck Durfee
Lead Software Architect, CentreSuite
TSYS iSolutions, Golden
Email [email protected]mailto:[email protected]

Ivan Porto C. <[email protected]mailto:[email protected]>
Sent by:
[email protected]mailto:[email protected]

09/30/2009 07:56 AM
Please respond to
[email protected]mailto:[email protected]

To

[email protected]mailto:[email protected]

cc

Subject

Re: [Ironruby-core] Clear ScriptEngine Global Variables

if (Runtime.Globals.ContainsVariable(className))
Runtime.Globals.RemoveVariable(className);


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nzhttp://flanders.co.nz/
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Wed, Sep 30, 2009 at 3:43 PM, Aaron C.
<[email protected]mailto:[email protected]> wrote:
Hi,

Is there anyway to clear all global variables from the IronRuby script
engine?

For example if I define a variable in a script and execute it:

$myVar = “Hello”

And then execute another script in a new scriptscope but with the same
ScriptEngine instance and use:

global_variables.each do |var|
print(“#{var} = #{eval(‘$’ + var)}”)
end

Then the myVar variable from the first instance will be listed.

Thanks,

Aaron

Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core


The information contained in this communication (including any
attachments hereto) is confidential and is intended solely for the
personal and confidential use of the individual or entity to whom it is
addressed. If the reader of this message is not the intended recipient
or an agent responsible for delivering it to the intended recipient, you
are hereby notified that you have received this communication in error
and that any review, dissemination, copying, or unauthorized use of this
information, or the taking of any action in reliance on the contents of
this information is strictly prohibited. If you have received this
communication in error, please notify us immediately by e-mail, and
delete the original message. Thank you