Ignore:
Timestamp:
Nov 28, 2007, 8:29:12 AM (13 years ago)
Author:
Pascal Terjan
Message:
  • Allow calling Caca::Display.new without parameter
File:
1 edited

Legend:

Unmodified
Added
Removed
  • libcaca/trunk/ruby/caca-display.c

    r2051 r2092  
    3131}
    3232
    33 static VALUE display_initialize(VALUE self, VALUE cv)
     33static VALUE display_initialize(int argc, VALUE* argv, VALUE self)
    3434{
    3535    caca_display_t *display;
    36    
    37     if(CLASS_OF(cv) != cCanvas)
    38     {
    39         rb_raise(rb_eArgError, "Argument is not a Cucul::Canvas");
    40     }
    41 
    42     display = caca_create_display(DATA_PTR(cv));
     36    VALUE cv;
     37
     38    rb_scan_args(argc, argv, "01", &cv);
     39
     40    if(NIL_P(cv))
     41    {
     42        display = caca_create_display(NULL);
     43    }
     44    else
     45    {
     46        if(CLASS_OF(cv) != cCanvas)
     47        {
     48            rb_raise(rb_eArgError, "Argument is not a Cucul::Canvas");
     49        }
     50
     51        display = caca_create_display(DATA_PTR(cv));
     52    }
     53
    4354    if(display == NULL)
    4455    {
     
    188199    rb_define_alloc_func(cDisplay, display_alloc);
    189200
    190     rb_define_method(cDisplay, "initialize", display_initialize, 1);
     201    rb_define_method(cDisplay, "initialize", display_initialize, -1);
    191202    rb_define_method(cDisplay, "refresh", display_refresh, 0);
    192203    rb_define_method(cDisplay, "time=", set_time, 1);
Note: See TracChangeset for help on using the changeset viewer.