Re: [IronPython] CodeContext went from language-independent to IronPython-specific
The only shared type system that exists in DLRland is the CLR type system. Individual DLR-based languages are free to define their types with the semantics similar to "list" (or "dictionary" or any other type). I think the most general thing you can do in a case like this is to make sure that the object you return implements both IList and IList. The natural candidate is List. On Mon, Mar 22, 2010 at 7:08 AM, Paul Felix wrote: > Thanks, Tomas and Curt. I see your blogs on this topic. > > Let's say I wanted to use the DynamicObject approach, and I have a dynamic > C# object with a runtime member called SomeMember. Let's say SomeMember is a > .NET List, but I want the object to return a calling-language-specific list > type. How could I perform a language-specific conversion? > > In other words, with my scriptable application, I might want to better > support the scriptwriter's language by returning language-specific types. If > a scriptwriter is using Python, it would be nice to return a Python list for > SomeMember. If the scriptwriter is using Ruby, it would be nice to return a > Ruby list. > > If there was some way to get access to a type converter based on the > "calling context", this might be doable. > > Does that make sense? > > > On Sun, Mar 21, 2010 at 8:53 PM, Paul Felix wrote: > >> Hi, >> >> I am embedding IronPython in an application for scripting. I'm also making >> some C# classes "dynamic" by implementing the special DLR methods like >> GetBoundMember. My signatures for those special methods include the code >> context: >> >> [System.Runtime. >> CompilerServices.SpecialName] >> public object GetBoundMember(CodeContext codeContext, string name) >> { >> . . . >> } >> >> I make use of the code context to get access to an object that essentially >> represents an application-defined context. I like the idea of being able to >> support other dynamic languages like IronRuby in the future, and I was >> bolstered by the fact that I could implement the special DLR methods with >> Microsoft.Scripting namespaces only (no IronPython namespaces). >> >> But in the newer versions of IronPython, the CodeContext type has been >> moved to an IronPython namespace, thus locking me in to IronPython. To >> remain independent of any dynamic language, am I going to have to implement >> the special DLR methods without the code context and find some other way to >> get at my app object? >> >> Thanks, >> Paul >> >> > > ___ > 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] CodeContext went from language-independent to IronPython-specific
Thanks, Tomas and Curt. I see your blogs on this topic. Let's say I wanted to use the DynamicObject approach, and I have a dynamic C# object with a runtime member called SomeMember. Let's say SomeMember is a .NET List, but I want the object to return a calling-language-specific list type. How could I perform a language-specific conversion? In other words, with my scriptable application, I might want to better support the scriptwriter's language by returning language-specific types. If a scriptwriter is using Python, it would be nice to return a Python list for SomeMember. If the scriptwriter is using Ruby, it would be nice to return a Ruby list. If there was some way to get access to a type converter based on the "calling context", this might be doable. Does that make sense? On Sun, Mar 21, 2010 at 8:53 PM, Paul Felix wrote: > Hi, > > I am embedding IronPython in an application for scripting. I'm also making > some C# classes "dynamic" by implementing the special DLR methods like > GetBoundMember. My signatures for those special methods include the code > context: > > [System.Runtime. > CompilerServices.SpecialName] > public object GetBoundMember(CodeContext codeContext, string name) > { > . . . > } > > I make use of the code context to get access to an object that essentially > represents an application-defined context. I like the idea of being able to > support other dynamic languages like IronRuby in the future, and I was > bolstered by the fact that I could implement the special DLR methods with > Microsoft.Scripting namespaces only (no IronPython namespaces). > > But in the newer versions of IronPython, the CodeContext type has been > moved to an IronPython namespace, thus locking me in to IronPython. To > remain independent of any dynamic language, am I going to have to implement > the special DLR methods without the code context and find some other way to > get at my app object? > > Thanks, > Paul > > ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] CodeContext went from language-independent to IronPython-specific
The proper "DLRish" way to make a C# class "dynamic" is to implement IDynamicMetaObjectProvider. The easiest way to do so for most purposes is to derive from DynamicObject. GetBoundMember is purely an IronPython mechanism. Indeed, anything that uses CodeContext is purely IronPython and will not give you dynamic behavior with any other DLR-based language. On Sun, Mar 21, 2010 at 5:53 PM, Paul Felix wrote: > Hi, > > I am embedding IronPython in an application for scripting. I'm also making > some C# classes "dynamic" by implementing the special DLR methods like > GetBoundMember. My signatures for those special methods include the code > context: > > [System.Runtime. > CompilerServices.SpecialName] > public object GetBoundMember(CodeContext codeContext, string name) > { > . . . > } > > I make use of the code context to get access to an object that essentially > represents an application-defined context. I like the idea of being able to > support other dynamic languages like IronRuby in the future, and I was > bolstered by the fact that I could implement the special DLR methods with > Microsoft.Scripting namespaces only (no IronPython namespaces). > > But in the newer versions of IronPython, the CodeContext type has been > moved to an IronPython namespace, thus locking me in to IronPython. To > remain independent of any dynamic language, am I going to have to implement > the special DLR methods without the code context and find some other way to > get at my app object? > > Thanks, > Paul > > > ___ > 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] CodeContext went from language-independent to IronPython-specific
Could you be specific about your scenario? What exactly is an "application-defined context" and the classes that would need an access such object? Tomas From: users-boun...@lists.ironpython.com [mailto:users-boun...@lists.ironpython.com] On Behalf Of Paul Felix Sent: Sunday, March 21, 2010 5:54 PM To: users@lists.ironpython.com Subject: [IronPython] CodeContext went from language-independent to IronPython-specific Hi, I am embedding IronPython in an application for scripting. I'm also making some C# classes "dynamic" by implementing the special DLR methods like GetBoundMember. My signatures for those special methods include the code context: [System.Runtime. CompilerServices.SpecialName] public object GetBoundMember(CodeContext codeContext, string name) { . . . } I make use of the code context to get access to an object that essentially represents an application-defined context. I like the idea of being able to support other dynamic languages like IronRuby in the future, and I was bolstered by the fact that I could implement the special DLR methods with Microsoft.Scripting namespaces only (no IronPython namespaces). But in the newer versions of IronPython, the CodeContext type has been moved to an IronPython namespace, thus locking me in to IronPython. To remain independent of any dynamic language, am I going to have to implement the special DLR methods without the code context and find some other way to get at my app object? Thanks, Paul ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
[IronPython] CodeContext went from language-independent to IronPython-specific
Hi, I am embedding IronPython in an application for scripting. I'm also making some C# classes "dynamic" by implementing the special DLR methods like GetBoundMember. My signatures for those special methods include the code context: [System.Runtime. CompilerServices.SpecialName] public object GetBoundMember(CodeContext codeContext, string name) { . . . } I make use of the code context to get access to an object that essentially represents an application-defined context. I like the idea of being able to support other dynamic languages like IronRuby in the future, and I was bolstered by the fact that I could implement the special DLR methods with Microsoft.Scripting namespaces only (no IronPython namespaces). But in the newer versions of IronPython, the CodeContext type has been moved to an IronPython namespace, thus locking me in to IronPython. To remain independent of any dynamic language, am I going to have to implement the special DLR methods without the code context and find some other way to get at my app object? Thanks, Paul ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] CodeContext
I don't know if I missed a conclusion to this but there is a general way to get a CodeContext. A CodeContext is just a Scope and a LanguageContext. You can new up an empty scope and you can get a LanguageContext from HostingHelpers.GetLanguageContext. But all of this breaks the remoting story. If that's an issue for you there's always HostingHelpers.CallEngine which will give you the LanguageContext and run your code in the ScriptRuntime's app domain. But more on point you could also look at RuntimeHelpers.GetDynamicStackFrames which might give you the information you want w/ an easier to use interface from C#. If there's an interesting exception related goal in here we could look at adding it to the ExceptionOperations class. From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Huzaifa Sent: Saturday, August 23, 2008 8:31 PM To: users@lists.ironpython.com Subject: Re: [IronPython] CodeContext I am try to get traceback object , for that i am trying different things Tomas Matousek wrote: The class might be actually be called ExceptionService in your bits. It was renamed recently. Tomas -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tomas Matousek Sent: Saturday, August 23, 2008 7:53 PM To: Discussion of IronPython Subject: Re: [IronPython] CodeContext Does ExceptionOeprations class provide you the information you need or is something missing? You can get an instance via engine.GetService(). Tomas -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Huzaifa Sent: Saturday, August 23, 2008 4:56 PM To: users@lists.ironpython.com Subject: [IronPython] CodeContext how to get CodeContext from ScriptRuntime ,ScriptScope or ScriptEngine . basically i am try use this function: public static PythonTuple/*!*/ GetExceptionInfoLocal(CodeContext/*!*/ context, Exception ex) -- View this message in context: http://www.nabble.com/CodeContext-tp19126500p19126500.html Sent from the IronPython mailing list archive at Nabble.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 View this message in context: Re: CodeContext<http://www.nabble.com/CodeContext-tp19126500p19127475.html> Sent from the IronPython mailing list archive<http://www.nabble.com/IronPython-f14449.html> at Nabble.com. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] CodeContext
I see. We probably should have a method on ExceptionOperations that returns a list of stack frame information given an exception. There is also a private method on PythonOps that creates the traceback object and doesn't require CodeContext: CreateTraceBack. We might consider making it public. Curt? Meanwhile, you can use GetExceptionInfoLocal with a default context from DefaultContext.Default. The only place where the context is used is to do some magic with StringException, but that doesn't influence the traceback object. Tomas From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Huzaifa Sent: Saturday, August 23, 2008 8:31 PM To: users@lists.ironpython.com Subject: Re: [IronPython] CodeContext I am try to get traceback object , for that i am trying different things Tomas Matousek wrote: The class might be actually be called ExceptionService in your bits. It was renamed recently. Tomas -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tomas Matousek Sent: Saturday, August 23, 2008 7:53 PM To: Discussion of IronPython Subject: Re: [IronPython] CodeContext Does ExceptionOeprations class provide you the information you need or is something missing? You can get an instance via engine.GetService(). Tomas -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Huzaifa Sent: Saturday, August 23, 2008 4:56 PM To: users@lists.ironpython.com Subject: [IronPython] CodeContext how to get CodeContext from ScriptRuntime ,ScriptScope or ScriptEngine . basically i am try use this function: public static PythonTuple/*!*/ GetExceptionInfoLocal(CodeContext/*!*/ context, Exception ex) -- View this message in context: http://www.nabble.com/CodeContext-tp19126500p19126500.html Sent from the IronPython mailing list archive at Nabble.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 View this message in context: Re: CodeContext<http://www.nabble.com/CodeContext-tp19126500p19127475.html> Sent from the IronPython mailing list archive<http://www.nabble.com/IronPython-f14449.html> at Nabble.com. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] CodeContext
I am try to get traceback object , for that i am trying different things Tomas Matousek wrote: > > The class might be actually be called ExceptionService in your bits. It > was renamed recently. > > Tomas > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Tomas Matousek > Sent: Saturday, August 23, 2008 7:53 PM > To: Discussion of IronPython > Subject: Re: [IronPython] CodeContext > > Does ExceptionOeprations class provide you the information you need or is > something missing? You can get an instance via engine.GetService(). > > Tomas > > -Original Message- > From: [EMAIL PROTECTED] > [mailto:[EMAIL PROTECTED] On Behalf Of Huzaifa > Sent: Saturday, August 23, 2008 4:56 PM > To: users@lists.ironpython.com > Subject: [IronPython] CodeContext > > > how to get CodeContext from ScriptRuntime ,ScriptScope or ScriptEngine . > > basically i am try use this function: > > > public static PythonTuple/*!*/ GetExceptionInfoLocal(CodeContext/*!*/ > context, Exception ex) > > > > -- > View this message in context: > http://www.nabble.com/CodeContext-tp19126500p19126500.html > Sent from the IronPython mailing list archive at Nabble.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 > > -- View this message in context: http://www.nabble.com/CodeContext-tp19126500p19127475.html Sent from the IronPython mailing list archive at Nabble.com. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com
Re: [IronPython] CodeContext
The class might be actually be called ExceptionService in your bits. It was renamed recently. Tomas -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Tomas Matousek Sent: Saturday, August 23, 2008 7:53 PM To: Discussion of IronPython Subject: Re: [IronPython] CodeContext Does ExceptionOeprations class provide you the information you need or is something missing? You can get an instance via engine.GetService(). Tomas -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Huzaifa Sent: Saturday, August 23, 2008 4:56 PM To: users@lists.ironpython.com Subject: [IronPython] CodeContext how to get CodeContext from ScriptRuntime ,ScriptScope or ScriptEngine . basically i am try use this function: public static PythonTuple/*!*/ GetExceptionInfoLocal(CodeContext/*!*/ context, Exception ex) -- View this message in context: http://www.nabble.com/CodeContext-tp19126500p19126500.html Sent from the IronPython mailing list archive at Nabble.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
Re: [IronPython] CodeContext
Does ExceptionOeprations class provide you the information you need or is something missing? You can get an instance via engine.GetService(). Tomas -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Huzaifa Sent: Saturday, August 23, 2008 4:56 PM To: users@lists.ironpython.com Subject: [IronPython] CodeContext how to get CodeContext from ScriptRuntime ,ScriptScope or ScriptEngine . basically i am try use this function: public static PythonTuple/*!*/ GetExceptionInfoLocal(CodeContext/*!*/ context, Exception ex) -- View this message in context: http://www.nabble.com/CodeContext-tp19126500p19126500.html Sent from the IronPython mailing list archive at Nabble.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
[IronPython] CodeContext
how to get CodeContext from ScriptRuntime ,ScriptScope or ScriptEngine . basically i am try use this function: public static PythonTuple/*!*/ GetExceptionInfoLocal(CodeContext/*!*/ context, Exception ex) -- View this message in context: http://www.nabble.com/CodeContext-tp19126500p19126500.html Sent from the IronPython mailing list archive at Nabble.com. ___ Users mailing list Users@lists.ironpython.com http://lists.ironpython.com/listinfo.cgi/users-ironpython.com