Instead of "global server" you want "import server". Another option here might be to put this global object into the built-in module and then it would simply be available to all scripts all the time.
You can do that via engine.GetBuiltinModule (it's an extension method defined in IronPython.Hosting). Then you can inject your value in. But then it'll be seen by all scripts. From there you might consider making your one global object be backed by a thread static so that you can get per-request isolation. -----Original Message----- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Patrick van der Willik Sent: Tuesday, June 16, 2009 2:14 AM To: Discussion of IronPython Subject: Re: [IronPython] Embedding IronPython and calling python functions from C# 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. def OnConnect(user): global server server.log.Write("Test") 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... Patrick 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. > _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com _______________________________________________ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com