c - Access struct in Python using SWIG -


do have redefine given struct (given in .c file, included in compilation) in interface file make accessible via python?

edit: if defined in header file, have include header file in interface file, right?

i think don't have to, except want add member functions c structures.

/* file : vector.h */ ... typedef struct {     double x,y,z; } vector;   // file : vector.i %module mymodule %{     #include "vector.h" %}  %include "vector.h"          // grab original c header file 

adding member functions c structures

/* file : vector.h */ ... typedef struct {     double x,y,z; } vector;   // file : vector.i %module mymodule %{     #include "vector.h" %} %extend vector {             // attach these functions struct vector     vector(double x, double y, double z) {         vector *v;         v = (vector *) malloc(sizeof(vector));         v->x = x;         v->y = y;         v->z = z;         return v;     }     ~vector() {         free($self);     }     double magnitude() {         return sqrt($self->x*$self->x+$self->y*$self->y+$self->z*$self->z);     }     void print() {         printf("vector [%g, %g, %g]\n", $self->x,$self->y,$self->z);     } }; 

swig-1.3 documentation


Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -