« Return to Thread: SWIG and Ruby Arrays
Message: 1
Date: Wed, 7 May 2008 15:39:22 -0600
From: "Bryan Richardson" <btrichardson@...>
Subject: [Swig-user] SWIG and Ruby Arrays
To: swig-user@...
Message-ID:
<3f81a4240805071439q54cca4abj230ac79aefd8ce82@...>
Content-Type: text/plain; charset="iso-8859-1"
Hello all,
I'm new to SWIG, so please bear with me! :) I have a C program that among
other things defines a structure and has a method that accepts an array of
those structures, similar to the following:
/* people.h header file */
typedef struct {
char* name;
} Person;
void say_hello(Person[] people);
/* source file */
#include <stdio.h>
#include "people.h"
void say_hello(int count, Person* people) {
int index;
for (index = 0; index < count; index++) {
printf("Hello, my name is %s\n", people[index]);
}
}
I'm using SWIG to wrap this library (in an Example module) so I can call it
from Ruby. From Ruby, I can create new Person objects and set their names
no problem. However, when I put them into a Ruby array and then try to send
that array to the say_hello method I get an error:
p1 = Example::Person.new
p1.name = "Bryan"
p2 = Person.new
p2.name = "John"
a = Array.new
a << p1
a << p2
Example.say_hello(a.length, a)
TypeError: in method 'say_hello', argument 2 of type 'Person *'
Can anyone tell me how I can configure SWIG such that I can create and pass
arrays like this?
--
Thanks!
Bryan
« Return to Thread: SWIG and Ruby Arrays
| Free Forum Powered by Nabble | Forum Help |