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.
|
Showing messages 1 through 2 of 2.
-
Use rb_scan_args()
2004-11-19 15:44:38
rooneg
[View]
-
Use rb_scan_args()
2004-11-19 15:44:27
djberg96
[View]