Women in Technology

Hear us Roar



Article:
  Extending Ruby with C
Subject:   Use rb_scan_args()
Date:   2004-11-19 15:40:58
From:   djberg96
You should do manual argument counting in variable length argument lists. Use rb_scan_args() instead. In writer_begin_element() for example, it should look like this:

static VALUE
writer_begin_element (int argc, VALUE *argv, VALUE self)
{
genxWriter w;
VALUE rbName, rbXmlns;

/* One mandatory, one optional argument */
rb_scan_args(argc,argv,"11",&rbName,&rbXmlns);

Check_Type(rbName,T_STRING);
if(Qnil != rbXmlns)
Check_Type(rbXmlns,T_STRING);
...

The front end API would then be:


Genx::Writer#begin_element(name,namespace=nil)


This is more concise, and less prone to error than checking argc manually.

Full Threads Newest First

Showing messages 1 through 2 of 2.

  • Use rb_scan_args()
    2004-11-19 15:44:27  djberg96 [View]

    You should NOT do ...

    Give me a preview button!
  • Use rb_scan_args()
    2004-11-19 15:44:38  rooneg [View]

    Thanks for the pointer, when I get a chance I'll make those changes to the current version of GenX4r.