From: trebor777 Date: 2007-06-08T10:46:11+09:00 Subject: Wrapping a structure as a new class... well i don't know if my title is exactly what i mean... anyway I'm writing a C extension, which can create a Bitmap class.(I'm using SDL) So far, it's working.. for the initialization: //======================================== VALUE cBitmap; void sdl_freeSurface(SDL_Surface* surface) { SDL_FreeSurface(surface); } VALUE bitmap_init(int argc, VALUE *argv, VALUE self) { SDL_Surface *new_bitmap; if (argc == 1) { Check_Type(argv[0],T_STRING); new_bitmap=IMG_Load(STR2CSTR(argv[0])); } else { Check_Type(argv[0],T_FIXNUM); Check_Type(argv[1],T_FIXNUM); new_bitmap=SDL_CreateRGBSurface(SDL_HWSURFACE,FIX2UINT(argv[0]),FIX2UINT(argv[1]),32,0,0,0,0); } return Data_Wrap_Struct(cBitmap,0,sdl_freeSurface,new_bitmap); } //========================================================= when i do a=Bitmap.new(23,32) i got a bitmap object. but here comes the problem: I got an argument type error on the class methods...(a.width for example): "wrong argument type Bitmap " I've understand that the wrapped structure is a T_DATA object.... but all I want is to access this structure. a class method example using which try to access the struct: //=============================== VALUE bitmap_width(VALUE obj) { SDL_Surface *surface; Data_Get_Struct(obj,SDL_Surface,surface); return INT2FIX(surface->w); } //=============================== If i use the 'self' argument in the Data_wrap instead of cBitmap, I can't create the object and got the same error: '........ type Bitmap ' So if someone can explain me :p how to get back my structure...please. ^^ would be great! -- View this message in context: http://www.nabble.com/Wrapping-a-structure-as-a-new-class...-tf3887307.html#a11019236 Sent from the ruby-talk mailing list archive at Nabble.com.