0

I have a working C program and now I'm embedding a python script implementing a specific function.

The question is, the arguments passed into Python is a complicated(I mean nested) C structure defined in C. And I hope the solution would be able to do the two ways communication easily:

1.Create structure in C, and pass it into Python. Let the Python do some modification.

2.Create the structure in Python. And pass it back to C.

I was trying "SWIG" to generate some wrappers for the structure, as well as some helper functions using SWIG for Python so that it could return me some nested part of the structure so that I could visit the structure through Python easily.

Will this be a good solution or I may miss some very simple way of solving it?

SandBag_1996
  • 1,570
  • 3
  • 20
  • 50
Chi
  • 55
  • 9
  • It's not easy, you need a `PyTypeObject`, specifically the `tp_members` search python's c api documentation for more information. – Iharob Al Asimi Mar 26 '15 at 01:17
  • In my experience, SWIG should be able to handle arbitrarily nested structs the way you'd "expect". Are there any specific problems you're having getting it to work? – brunobeltran0 Mar 26 '15 at 02:18
  • @brunobeltran0 not for now cuz i just started. But I didn't find lots of similar works except the one[link](http://forums.indiegamer.com/showthread.php?14280-Embending-Python-into-C-C-how-to-send-a-C-structure-to-Python) so I was worried about the direction I made. Thank you anyway : ) – Chi Mar 26 '15 at 03:20
  • See http://stackoverflow.com/questions/9040669/how-can-i-implement-a-c-class-in-python-to-be-called-by-c/9042139#9042139 – Flexo Mar 27 '15 at 06:22

1 Answers1

0

In my experience, SWIG should be able to handle arbitrarily nested structs the way you'd "expect". – brunobeltran0

Armali
  • 18,255
  • 14
  • 57
  • 171