[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Data_Wrap_Struct

Thomas Sondergaard

9/27/2003 3:05:00 PM

Is it okay to wrap something that is not a struct with Data_Wrap_Struct?
Like this where I just wrap an int?

VALUE DotNetObjectToRubyObject(VALUE klass, System::Object *anObject) {
GCHandle gchandle = GCHandle::Alloc(anObject);
int *handle = ALLOC(int);
*handle = GCHandle::op_Explicit(gchandle).ToInt32();
return Data_Wrap_Struct(klass, 0, DotNetHandle_free, handle);
}

Thomas


2 Answers

Lyle Johnson

9/27/2003 3:17:00 PM

0

Thomas Sondergaard wrote:

> Is it okay to wrap something that is not a struct with Data_Wrap_Struct?

Yes. Ruby doesn''t know (or care) what it is that the data pointer points to.

Sean O'Dell

9/27/2003 5:08:00 PM

0

Thomas Sondergaard wrote:
> Is it okay to wrap something that is not a struct with Data_Wrap_Struct?
> Like this where I just wrap an int?
>
> VALUE DotNetObjectToRubyObject(VALUE klass, System::Object *anObject) {
> GCHandle gchandle = GCHandle::Alloc(anObject);
> int *handle = ALLOC(int);
> *handle = GCHandle::op_Explicit(gchandle).ToInt32();
> return Data_Wrap_Struct(klass, 0, DotNetHandle_free, handle);
> }

Sure, anything will do. =)

Sean O''Dell