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
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.
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