Reputation: 51
I'm using SWIG to make my C code work on php...But I don't figure out how to write a good interface based on my C code to pass to SWIG.Can somebody help me? The link to see what my C code looks like is this one : http://www.pastie.org/1739618 Thanks a lot for your help
Upvotes: 0
Views: 386
Reputation: 5156
Some things that often don't work well across languages, with the use of SWIG:
Upvotes: 0
Reputation: 7363
You should move your function prototypes to a separate header file. SWIG can process that and generate the required stuff for you. You can follow the SWIG tutorial and specifically pay attention to the section SWIG for the truly lazy which shows how you can avoid having to maintain a separate SWIG interface file.
Combine this with the information from the SWIG and PHP page and you should be able to make things work. Note that SWIG does not support PHP4.
Maybe you can start by trying something like the following out and using it as the input to the swig
command:
/* optim_wizard_5.h */
#ifdef SWIG
%module optim_wizard_5
%{
#include "optim_wizard_5.h"
%}
#endif
/* Function prototypes to define later */
void *getCpc(void *ptr);
float getCpc_max(float *arg);
char *do_web_request(char *url);
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp);
float request_cpc();
Upvotes: 1