/*
 * call-seq:
 *    Win32::API::Callback.new(prototype, return='L')
 * 
 * Creates and returns a new Win32::API::Callback object. The +function+ is
 * the name of the Windows function.
 * 
 * The +prototype+ is the function prototype for the callback function. This
 * is a string. The possible valid characters are 'I' (integer), 'L' (long),
 * 'V' (void), or 'P' (pointer). Unlike API objects, API::Callback objects
 * do not have a default prototype.
 * 
 * The +return+ argument is the return type for the callback function. The
 * valid characters are the same as for the +prototype+. The default is
 * 'L' (long).
 */
static VALUE callback_init(int argc, VALUE* argv, VALUE self)
{
   VALUE v_proto, v_return, v_proc;
   int i;
    
   rb_scan_args(argc, argv, "11", &v_proto, &v_return);
   
   /* Validate prototype characters */
   for(i = 0; i < RSTRING(v_proto)->len; i++){
      switch(RSTRING(v_proto)->ptr[i]){
         case 'I': case 'L': case 'P': case 'V':
            break;
         default:
            rb_raise(cCallbackError, "Illegal prototype '%c'",
               RSTRING(v_proto)->ptr[i]);
      }
   }

   if(NIL_P(v_return) || RARRAY(v_return)->len == 0)
      v_return = rb_str_new2("L");

   if(rb_block_given_p())
      v_proc = rb_block_proc();
   else
      v_proc = Qnil;

    rb_iv_set(self, "@function", v_proc);
    rb_iv_set(self, "@prototype", v_proto);
    rb_iv_set(self, "@return_type", v_return);
    
    return self;
}