[IronPython] IP v8 Hosting question...

Alex Henderson alex at syzmk.com
Tue Jun 27 02:03:16 CEST 2006


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




More information about the Ironpython-users mailing list