/* * call-seq: * new( n ) -> Joystick * * Create and initialize an interface to the nth joystick on the * system. Raises SDLError if the joystick could not be opened. */ VALUE rbgm_joystick_new( int argc, VALUE *argv, VALUE module) { VALUE self; SDL_Joystick *joy; int index; if(argc < 1) rb_raise(rb_eArgError,"wrong number of arguments (%d for 1)",argc); index = NUM2INT(argv[0]); joy = SDL_JoystickOpen(index); if(joy == NULL) { rb_raise(eSDLError,"Could not open joystick %d: %s",\ index,SDL_GetError()); } self = Data_Wrap_Struct(cJoy, 0,SDL_JoystickClose, joy); rb_obj_call_init(self,argc,argv); return self; }