You are correct about what I'm trying to do, sorry if wrote it in a way that was hard to understand. The project I'm working on this for is a 2-D game engine. I plan on calling python functions from C# with the relevant class (say on a collision with the colliding objects as parameters) but if extra data is needed about other items it can retrieve the list of them and these python function will need to execute quickly. With modules I can make different ways to access the wrapper classes I have made because in have the internal structure and can retrieve smaller sets based off whet the script calls and it won't need to pick through it or if it does the set would not be as big. I also want to maintain backwards compatibility as I add more functionality and if I set variables I worried about a script already using the variable and I use one class it would probably have a very large hierarchy or lots of unrelated functions which I want to avoid passing into python.

An unrelated issue I have with ScriptScope is I can't figure out to add overloaded functions with different parameter counts for defaults I'm using 3.5 if it matters.

Thanks
Ross


--------------------------------------------------
From: "Jeff Hardy" <jdha...@gmail.com>
Sent: Tuesday, June 22, 2010 11:26 AM
To: "Discussion of IronPython" <users@lists.ironpython.com>
Subject: Re: [IronPython] Modules in hosted enviroment

Hi Ross,
Sorry if I'm being dense, but here's how I understand what you're doing:

- you're hosting IronPython in some program X
- X will generate data D and somehow feed D to Python script Y
- Y will transform or process D in some way

What you're looking for is the best way to get D into Y, correct?

I think creating a module is the wrong way to go about this; modules
are supposed to contain code and constant data, as the IronPython
engine will only load them once and share them.

Why is setting a variable for the Python script to use not suitable?
If it needs to be a complex object, you can create a (non-static)
class in C#, fill it out, and pass an instance to the Python script
using ScriptScope.SetVariable.

- Jeff

On Tue, Jun 22, 2010 at 8:41 AM, Ross Hammermeister <glitc...@gmail.com> wrote:
My program creates data for a python script to use and I though the best way for it get access to this was with modules. Simply setting a variable in the script would not work because of the complexity of the data. Using the clr module will not get access to the existing data (I also do not want to grant access to all the other libraries). So I am left with creating a module but using a static class and assigning all the instances to the static classes
every time before I call the python script is not a great method but I'm
thinking this would be the best at this point. The other method I found was using the IronPython.Runtime.PythonModule class and Creating an instance for
each of my modules and adding to using
PythonEngine.Runtime.Globals.SetVariable The procedure to do this doesn't
give the impression that what I'm doing was ever intended and I have hit
things that I cannot do using this method. So I'm looking for a good method
of creating modules that would have my data attached to them.

Thanks
Ross

--------------------------------------------------
From: "Jeff Hardy" <jdha...@gmail.com>
Sent: Monday, June 21, 2010 11:24 AM
To: "Discussion of IronPython" <users@lists.ironpython.com>
Subject: Re: [IronPython] Modules in hosted enviroment

On Sat, Jun 19, 2010 at 10:51 PM, Ross Hammermeister <glitc...@gmail.com>
wrote:

I have a project where I am hosting IronPython and I was wondering what
is
the best way to create modules in C# for python to use. I have found two
ways to do it so far. One method is what is done in IronPython, where
static
classes and the PythonModule attribute are used but I don't want to use
static classes to access runtime data.

I'm not 100% sure what you mean here, but the static class is just a
container - and it can contain non-static classes (and functions, and
static variables, etc). If it needs to be a module, it's the way to
go, as far as I'm concerned. If things get too big, don't forget that
you can use partial classes to split things up.

However, depending on what your code does, you probably don't need to
make it a module - IronPython will work just fine with any .NET class
library. Just do a `clr.AddReference` and then import the classes.

- Jeff
_______________________________________________
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

_______________________________________________
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

Reply via email to