[IronPython] IP v8 Hosting question...

Shri Borde Shri.Borde at microsoft.com
Tue Jun 27 23:55:15 CEST 2006


We will are taking a look at the API and will be changing it a bit.

The current way of doing this as follows:

PythonEngine engine = new PythonEngine();

SymbolId id = SymbolTable.StringToId("Message");

ModuleScope scope1 = new ModuleScope("Junk1");
scope1.SetGlobal(id, "hello");

ModuleScope scope2 = new ModuleScope("Junk2");
scope2.SetGlobal(id, "goodbye");

Assert.AreEqual("hello", engine.Evaluate<string>("Message", scope1,
ExecutionOptions.Default));

Assert.AreEqual("goodbye", engine.Evaluate<string>("Message", scope2,
ExecutionOptions.Default));

Do you want to help develop Dynamic languages on CLR? (http://members.microsoft.com/careers/search/details.aspx?JobID=6D4754DE-11F0-45DF-8B78-DC1B43134038)

-----Original Message-----
From: users-bounces at lists.ironpython.com [mailto:users-bounces at lists.ironpython.com] On Behalf Of Alex Henderson
Sent: Monday, June 26, 2006 5:03 PM
To: 'Discussion of IronPython'
Subject: [IronPython] IP v8 Hosting question...

I'm looking for the most appropriate way to "scope" variables for my
expression to evaluate that come from an external context (ie. Outside of
the python engine) - So far I have something working, using ModuleScope -
but is this the way I should be doing it?

PythonEngine engine = new PythonEngine();

SymbolId id = SymbolTable.StringToId("Message");

ModuleScope scope1 = ModuleScope.MakeScopeForFunction(new
PythonModule("Junk", new Dict(), engine.Sys));
scope1.SetGlobal(id, "hello");

ModuleScope scope2 = ModuleScope.MakeScopeForFunction(new
PythonModule("Junk", new Dict(), engine.Sys));
scope2.SetGlobal(id, "goodbye");

Assert.AreEqual("hello", engine.Evaluate<string>("Message", scope1,
ExecutionOptions.Default));

Assert.AreEqual("goodbye", engine.Evaluate<string>("Message", scope2,
ExecutionOptions.Default));

Using this method I can evaluate around 2000 expressions a second, which is
more the adequate for what I'm doing - but I'm concerned about memory
consumption...

Chez,

 - Alex

_______________________________________________
users mailing list
users at lists.ironpython.com
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com



More information about the Ironpython-users mailing list