ONJava.com -- The Independent Source for Enterprise Java
oreilly.comSafari Books Online.Conferences.

advertisement

AddThis Social Bookmark Button
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.


1 to 2 of 2
1 to 2 of 2