I am using SWIG to wrap a C interface in Ruby. Given two structs
typedef struct Vertex {
int color, discoverd, finished;
struct Vertex *next;
} Vertex;
typedef struct Graph {
struct Vertex *vertex;
} Graph;
how can I create a #each
method which yields the current vertex, so that I can process it in Ruby. Currently my SWIG interface file contains something like
%extend Graph {
void each() {
Vertex *v;
v = self->vertex;
while(v) {
rb_yield(Qnil); // how do I yield a vertex?
v = v->next;
}
}
};
Thanks in advance for your help.
--t6d