I am trying to replace MATLAB/MEX and switch to Python. I came across SWIG, ctypes & Cython as possible solutions and started trying out SWIG (which seems very simple).
My C functions have variable argument lengths of the form main(int argc, char *argv[]). I found solutions online, but getting this working with SWIG lead to a lot of issues.
- Are the other methods (ctypes / Cython) any simpler?
- Any example to do this task with SWIG will be helpful.
There’s actually an example in the SWIG documentation for exactly this sort of function with Python. I’ve quoted it here with a minor change:
This allows you in Python to do simply:
Where
testis the name of the module you gave SWIG andfoois a function that matches the signatureint argc, char *argv[]. Simple and intuitive to use for a Python programmer and it encapsulates and reuses the complex bit.What the documentation doesn’t seem to mention though is that there’s an interface file that does all this for you already:
is sufficient.