Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python
If you're using C# 4.0 (comes with VS 2010/.NET 4) you can use the dynamic type to simplify this further: dynamic scope = engine.CreateScope(); scope.hash = new Dictionary(); scope.hash["key"] = "value"; On Thu, Jan 6, 2011 at 07:11, Ron Lindsey wrote: > Pascal, > > Well, I feel silly now. I was making it out to be too hard. Your example set > me on the right path. Thank you! > > Awesome user group! > > Thanks, Ron Lindsey > > On 1/5/2011 1:45 PM, Pascal Normandin wrote: >> >> Hello, >> >> Here is a simple way to call into C# variables from IronPython using a >> scope. >> >> var engine = IronPython.Hosting.Python.CreateEngine(); >> var scope = engine.CreateScope(); >> var dict = new Dictionary(); >> dict["key"] = "value"; >> scope.SetVariable("hash", dict); >> >> // Calling dict from IP >> engine.Execute("print hash['key']", scope); >> >> >> Pascal >> -Original Message- >> From: users-boun...@lists.ironpython.com >> [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey >> Sent: January-05-11 2:25 PM >> To: Daniel Jennings >> Cc: Discussion of IronPython >> Subject: Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python >> >> Daniel, >> >> Thanks for the reply. To your question, No. The real problem here is how >> do i get access to the variables in c# from ironpython. >> >> Thanks, Ron Lindsey >> >> On 1/5/2011 1:22 PM, Daniel Jennings wrote: >>> >>> Have you tried just treating it like a regular Python dictionary? I >> >> thought that's all I had to do, though I work with Dictionary, not >> Hashtable objects. >>> >>> -Original Message- >>> From: users-boun...@lists.ironpython.com >> >> [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey >>> >>> Sent: Wednesday, January 05, 2011 11:21 AM >>> To: users@lists.ironpython.com >>> Subject: [IronPython] IP 2.7b1 - Accessing C# variables from Python >>> >>> I have written an OpenGL 3D modeling program in C#/OpenTK. In the >>> program, I store all the objects (box, sphere, tube, etc) the user >>> created into a hashtable. Each object stored is of type Box, Sphere >>> etc... >>> >>> I am embedding IronPython to give the user a way to animate their >>> models. So in IronPython, the user needs to have access to the objects >>> in the hashtable to get/set properties of the different objects. >>> >>> Once the script is written, they then will run it. as the script >>> executes, it will control the objects in the hashtable, which in turn >>> will move the 3D models in the screen. >>> >>> I have looked/googled/read but have not found out a way to access a C# >>> hashtable and the objects stored with in it. >>> >>> Any ideas? >> >> ___ >> 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
Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python
Pascal, Well, I feel silly now. I was making it out to be too hard. Your example set me on the right path. Thank you! Awesome user group! Thanks, Ron Lindsey On 1/5/2011 1:45 PM, Pascal Normandin wrote: Hello, Here is a simple way to call into C# variables from IronPython using a scope. var engine = IronPython.Hosting.Python.CreateEngine(); var scope = engine.CreateScope(); var dict = new Dictionary(); dict["key"] = "value"; scope.SetVariable("hash", dict); // Calling dict from IP engine.Execute("print hash['key']", scope); Pascal -Original Message- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey Sent: January-05-11 2:25 PM To: Daniel Jennings Cc: Discussion of IronPython Subject: Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python Daniel, Thanks for the reply. To your question, No. The real problem here is how do i get access to the variables in c# from ironpython. Thanks, Ron Lindsey On 1/5/2011 1:22 PM, Daniel Jennings wrote: Have you tried just treating it like a regular Python dictionary? I thought that's all I had to do, though I work with Dictionary, not Hashtable objects. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey Sent: Wednesday, January 05, 2011 11:21 AM To: users@lists.ironpython.com Subject: [IronPython] IP 2.7b1 - Accessing C# variables from Python I have written an OpenGL 3D modeling program in C#/OpenTK. In the program, I store all the objects (box, sphere, tube, etc) the user created into a hashtable. Each object stored is of type Box, Sphere etc... I am embedding IronPython to give the user a way to animate their models. So in IronPython, the user needs to have access to the objects in the hashtable to get/set properties of the different objects. Once the script is written, they then will run it. as the script executes, it will control the objects in the hashtable, which in turn will move the 3D models in the screen. I have looked/googled/read but have not found out a way to access a C# hashtable and the objects stored with in it. Any ideas? ___ 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
Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python
Hello, Here is a simple way to call into C# variables from IronPython using a scope. var engine = IronPython.Hosting.Python.CreateEngine(); var scope = engine.CreateScope(); var dict = new Dictionary(); dict["key"] = "value"; scope.SetVariable("hash", dict); // Calling dict from IP engine.Execute("print hash['key']", scope); Pascal -Original Message- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey Sent: January-05-11 2:25 PM To: Daniel Jennings Cc: Discussion of IronPython Subject: Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python Daniel, Thanks for the reply. To your question, No. The real problem here is how do i get access to the variables in c# from ironpython. Thanks, Ron Lindsey On 1/5/2011 1:22 PM, Daniel Jennings wrote: > Have you tried just treating it like a regular Python dictionary? I thought that's all I had to do, though I work with Dictionary, not Hashtable objects. > > > -Original Message- > From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey > Sent: Wednesday, January 05, 2011 11:21 AM > To: users@lists.ironpython.com > Subject: [IronPython] IP 2.7b1 - Accessing C# variables from Python > > I have written an OpenGL 3D modeling program in C#/OpenTK. In the > program, I store all the objects (box, sphere, tube, etc) the user > created into a hashtable. Each object stored is of type Box, Sphere etc... > > I am embedding IronPython to give the user a way to animate their > models. So in IronPython, the user needs to have access to the objects > in the hashtable to get/set properties of the different objects. > > Once the script is written, they then will run it. as the script > executes, it will control the objects in the hashtable, which in turn > will move the 3D models in the screen. > > I have looked/googled/read but have not found out a way to access a C# > hashtable and the objects stored with in it. > > Any ideas? ___ 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
Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python
Daniel, Thanks for the reply. To your question, No. The real problem here is how do i get access to the variables in c# from ironpython. Thanks, Ron Lindsey On 1/5/2011 1:22 PM, Daniel Jennings wrote: Have you tried just treating it like a regular Python dictionary? I thought that's all I had to do, though I work with Dictionary, not Hashtable objects. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey Sent: Wednesday, January 05, 2011 11:21 AM To: users@lists.ironpython.com Subject: [IronPython] IP 2.7b1 - Accessing C# variables from Python I have written an OpenGL 3D modeling program in C#/OpenTK. In the program, I store all the objects (box, sphere, tube, etc) the user created into a hashtable. Each object stored is of type Box, Sphere etc... I am embedding IronPython to give the user a way to animate their models. So in IronPython, the user needs to have access to the objects in the hashtable to get/set properties of the different objects. Once the script is written, they then will run it. as the script executes, it will control the objects in the hashtable, which in turn will move the 3D models in the screen. I have looked/googled/read but have not found out a way to access a C# hashtable and the objects stored with in it. Any ideas? ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] IP 2.7b1 - Accessing C# variables from Python
Have you tried just treating it like a regular Python dictionary? I thought that's all I had to do, though I work with Dictionary, not Hashtable objects. -Original Message- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Ron Lindsey Sent: Wednesday, January 05, 2011 11:21 AM To: users@lists.ironpython.com Subject: [IronPython] IP 2.7b1 - Accessing C# variables from Python I have written an OpenGL 3D modeling program in C#/OpenTK. In the program, I store all the objects (box, sphere, tube, etc) the user created into a hashtable. Each object stored is of type Box, Sphere etc... I am embedding IronPython to give the user a way to animate their models. So in IronPython, the user needs to have access to the objects in the hashtable to get/set properties of the different objects. Once the script is written, they then will run it. as the script executes, it will control the objects in the hashtable, which in turn will move the 3D models in the screen. I have looked/googled/read but have not found out a way to access a C# hashtable and the objects stored with in it. Any ideas? -- Thanks, Ron Lindsey ___ 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
[IronPython] IP 2.7b1 - Accessing C# variables from Python
I have written an OpenGL 3D modeling program in C#/OpenTK. In the program, I store all the objects (box, sphere, tube, etc) the user created into a hashtable. Each object stored is of type Box, Sphere etc... I am embedding IronPython to give the user a way to animate their models. So in IronPython, the user needs to have access to the objects in the hashtable to get/set properties of the different objects. Once the script is written, they then will run it. as the script executes, it will control the objects in the hashtable, which in turn will move the 3D models in the screen. I have looked/googled/read but have not found out a way to access a C# hashtable and the objects stored with in it. Any ideas? -- Thanks, Ron Lindsey ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] Writing a Compiler framework: Static typing use of the DLR
Hello Tomas, Ideally I want the base functionality, for now, to mimic that of C#. There is other functionality extensions I plan on implementing (static duck-typing through explicitly defined type-parameter meta-data), but let's start with the basics: given each functional variation of a potential call, as an example, expression coercion through N-ary operators, implicit type conversions, and so on, are there different call site constructs to represent each in an intent based manner? An example being things that look like method invocations but could be properties that return a delegate, the real question is where does the DLR's functionality end and the language's specific use of the DLR begin? Further, your call sight Func, I'm guessing that encodes the types of the parameters as they exist at compile time, where object in the type-parameters has special meaning, and others represent points where further evaluation isn't necessary? Thanks, -Allen Copeland Jr. I'm not sure I understand what you want to achieve. Could you describe > functionality your framework provides? > > Every language that integrates with DLR might use a different way of > expressing late bound calls. C#'s dynamic type is one way of doing that. The > code that actually performs the dynamic dispatch via DLR call sites usually > looks like: > > // Lazy-initialize a dynamic call-site object; provide a language specific > binder that performs the runtime binding > if (site == null) { site = CallSite TResult>>>.Create(runtime_binder); } > > // call the Target delegate of the site. > result = Site.Target(Site, args); > > The runtime_binder for the site carries information about the dynamic > operation available at compile-time. This includes e.g. a method name, the > current accessibility context, etc. > ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] FW: Writing a Compiler framework: Static typing use of the DLR
Forwarding to d...@microsoft.com. I'm not sure I understand what you want to achieve. Could you describe functionality your framework provides? Every language that integrates with DLR might use a different way of expressing late bound calls. C#'s dynamic type is one way of doing that. The code that actually performs the dynamic dispatch via DLR call sites usually looks like: // Lazy-initialize a dynamic call-site object; provide a language specific binder that performs the runtime binding if (site == null) { site = CallSite>>.Create(runtime_binder); } // call the Target delegate of the site. result = Site.Target(Site, args); The runtime_binder for the site carries information about the dynamic operation available at compile-time. This includes e.g. a method name, the current accessibility context, etc. Tomas -Original Message- From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Alexander Morou Sent: Wednesday, January 05, 2011 6:39 AM To: Iron Python Mailing List Subject: [IronPython] Writing a Compiler framework: Static typing use of the DLR Hello, I'm not really sure where to ask this question, so I figured I'd ask on the mailing list of the project that largely started the DLR (assuming memory serves correctly.) I'm writing a compiler framework, and I was wondering what kind of work, in AST rewrites I would need to perform, or classes from the DLR object model I would need to use, in order to support, what C# calls, a static type dynamic? From what I can tell of C#, it uses its own model to wrap some of the concepts provided by the DLR, so I'm not exactly sure how to handle the late-bound dispatch so that it's marshaled by the appropriate language binder for a given object instance. I could go deeper into how C# does it, but I don't really like the idea of looking at the code that was written by someone else (since the only way I can look at it is through a disassembler), my own code rewritten by C#'s compiler is fine, but the innards of what that code uses: no. I understand the basic concept behind the DLR, but it's too complex to go over with a fine tooth comb. Search algorithms aren't sophisticated enough to ask questions like this through google or bing (especially on, largely intangible, intent in code), which is why I ask here. I originally asked Jeff Hardy (http://jdhardy.blogspot.com/) for insight, and he suggested I look here. Any insight anyone here can provide into this is appreciated. Thanks, -Allen [Alexander Morou] Copeland Jr. ___ 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
[IronPython] Writing a Compiler framework: Static typing use of the DLR
Hello, I'm not really sure where to ask this question, so I figured I'd ask on the mailing list of the project that largely started the DLR (assuming memory serves correctly.) I'm writing a compiler framework, and I was wondering what kind of work, in AST rewrites I would need to perform, or classes from the DLR object model I would need to use, in order to support, what C# calls, a static type dynamic? From what I can tell of C#, it uses its own model to wrap some of the concepts provided by the DLR, so I'm not exactly sure how to handle the late-bound dispatch so that it's marshaled by the appropriate language binder for a given object instance. I could go deeper into how C# does it, but I don't really like the idea of looking at the code that was written by someone else (since the only way I can look at it is through a disassembler), my own code rewritten by C#'s compiler is fine, but the innards of what that code uses: no. I understand the basic concept behind the DLR, but it's too complex to go over with a fine tooth comb. Search algorithms aren't sophisticated enough to ask questions like this through google or bing (especially on, largely intangible, intent in code), which is why I ask here. I originally asked Jeff Hardy (http://jdhardy.blogspot.com/) for insight, and he suggested I look here. Any insight anyone here can provide into this is appreciated. Thanks, -Allen [Alexander Morou] Copeland Jr. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com