|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
SWIG and Ruby ArraysHello 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 ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
Fwd: SWIG and Ruby ArraysHello 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 ------------------------------------------------------------------------- This SF.net email is sponsored by the 2008 JavaOne(SM) Conference Don't miss this year's exciting event. There's still time to save $100. Use priority code J8TL2D2. http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone _______________________________________________ Swig-user mailing list Swig-user@... https://lists.sourceforge.net/lists/listinfo/swig-user |
|
|
|
| Free Forum Powered by Nabble | Forum Help |