From: TAKANO Noriyuki Date: 2006-02-11T10:15:21+09:00 Subject: Re: Preserve value-type semantics in imported types sorry John, I forgot to paste the sample code, but it may not be necessary as you already know clone and dup. I have just browsed RubyCLR and some more. However, let me excuse writing here rather general things because I haven't read your program carefully. As you already know, we cannot assume classes of arguments when we make libraries in ruby, and types we use in ruby are not fully the same as those in the system. But I am not worried, wish neither would you be. It seems that the types you need to keep right are not of values inside ruby programs, but of those to interface to outside ruby, that is the places we carefully use ruby->C and C->ruby functions, right? Such type information in ruby objects shall be only accessible to read so that ruby applications do not change. I guess everybody overcome p2 = p1 and p2 = pl.clone strangeness sooner or later :-) greetings to you, Mathew, Ben and their mom... and more? nori John Lam wrote: >Thanks, Nori! > >Perhaps it wasn't super clear in my example, but this line of code: > >p = Point.new(3, 4) > >actually creates a new CLR Point value type inside of a Ruby VALUE object. A >CLR value type is an opaque blob of data (but in this case is really a >couple of 32 bit integers packed together), so I store it in a T_DATA >struct. So I allocate enough memory to hold the value type, and tell the CLR >to create the value type at the address of the T_DATA struct in the VALUE >object. > >X and Y are properties defined in the Point value type class in the CLR. >They map to accessor methods get/set_X and get/set_Y. My RubyCLR bridge maps >these things automagically through liberal use of const_missing and >method_missing. So I can't change these names even if they aren't >Ruby-esque. Those are the case-sensitive method and property names defined >by the value type in the CLR. > >I guess the real issue is that I don't think there's a way to force value >type semantics onto Ruby reference types. It would be nice to preserve CLR >value type semantics inside of Ruby, but hey- they're different type systems >so you need to abide by the rules of those type systems. > >I'm just worried that it might introduce bugs in code that use my bridge: > >p1 = p2 is just so much more intuitive than p1 = p2.clone > >If you're curious about my RubyCLR bridge, you can download my first public >drop of the bits here: >http://www.iunknown.com/articles/2006/01/12/first-drop-of-rubyclr > >I'm working on a new drop that marshals value types correctly - hence this >question on the list. Hopefully I'll have support early next week for folks >to play with. > >Thanks >-John >http://www.iunknown.com > > >