Question

Is there any tool available that takes C code as input and outputs valid PHP files?

I'd like to use the SAC API but all the implementations currently available are in C, Java, Ruby and Perl. I wonder if the C implementation can be converted to PHP easily.

Was it helpful?

Solution

I've never seen any tool to do that ; but the way that's generally used when one wants to use some C library from PHP is to write a PHP extension, that acts as some kind of "bridge" between the PHP userland-code, and the C library.

That's how you are able to use the curl library from PHP, for example.


A couple of interesting reads on that matter :

And, if you are really interested by the subject, and ready to spend some money on it, you could also buy the book Extending and Embedding PHP (some pages are available as preview on Google Books too) ; I've seen a couple of times that it was the book to read when interested on this subject (In fact, I've bought it some time ago, and it's an interesting read, even if you don't plan on writing an extension right now)

BTW, the author of that book is also the author of the first four articles I linked to ;-)

OTHER TIPS

The answer is The simplified wrapper and interface generator

It's a huge library and tool and has a steep learning curve so maybe you should ask yourself if the API you want to wrap is really complicated enough to use SWIG or if it's not faster to do it manually.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top