[IronPython] Embedding IronPython and calling python functions from C#
Patrick van der Willik
patrick at toolmaker.nl
Tue Jun 16 11:13:33 CEST 2009
Ok, I'm confused here. I'm very new to Python aswell, so this probably
doesn't help very much. As oppossed to trying to constanly import a huge
set of require variables all the time, I thought it might be a good idea
to introduce 1 object into the globals space which will host a variety
of the functions.
I did this by calling engine.Runtime.Globals.SetVariable("server",
server); then loading source script, compile it and invoke it on the scope.
However, this results in the same error, where server is not defined. I
feel kinda silly here, as to me is would seem rather logical that when I
introduce variables into a ScriptScope and then execute a function
within that scope that it would work. I understand that variables
themselfs are limited to a module, which sounds logical, but it feels
weird that even tho I inject a variable directly into the globals table
or into the scope that I created before executing a script on it, I
can't (in)directly use them from script.
The other solution would be to have the server object be part of every
function call to scripts, but that sounds kinda silly...
Dino Viehland wrote:
> You can set the variables in ScriptRuntime.Globals but then the user
> will need to import them from Globals to have access to them. There's no
> way to automatically expose globals to every script though.
More information about the Ironpython-users