how to wrap a c struct (array or even struct array member)

Asked by hangl

i want to wrap a such function to python :such as

typedef struct {
 int a;
 unsinged char b;
} InnerSt;

typedef struct {
 int c;
 InnerSt aist[10];
}OutterST;

void TestStruct(OutterST * pst)
{
----
}

I tried but no idea how to do? does pybindgen can do such job? what should i do ? thanks very much !

Question information

Language:
English Edit question
Status:
Answered
For:
PyBindGen Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Gustavo Carneiro (gjc) said :
#1

PyBindGen cannot wrap a C vector of an arbitrary type, like "InnerSt aist[10]". Sorry.

I suggest you make an API to get the elements of the vector:

InnerSt OuterST_GetItem(OutterST * pst, int index)
{
  return pst->aist[index];
}

Then you wrap OuterST_GetItem (perhaps function-as-method). Idem for a SetItem function.

Can you help with this problem?

Provide an answer of your own, or ask hangl for more information if necessary.

To post a message you must log in.