|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Language bindings
Hi all
I wasn't sure whether this should go in here or the C/C++ forum. Basically I have an application that has been written to take plugins but currently they can only be written in C or C++ as it was developed in C. How would I go about designing & implementing "language bindings" for a number of major languages (Java, Perl, Python and PHP)? Please note that this is all being run locally and I don't want to have to run a webservice to get these to talk to each other. Any tips, suggestions or resources would be helpful. Last edited by Thoku : April 19th, 2008 at 10:30 AM. |
|
#2
|
|||
|
|||
|
Take a look at SWIG.
Quote:
There are other tools that do a similar job for specific languages (e.g. Boost's Python library for interfacing between C++ and Python), but I dont know of any that supports as wide a range of languages as SWIG. However these tools are usually for making C/C++ libraries callable from the target language - it sounds like what you want is to go the other way, which may be more difficult. Dave |
|
#3
|
|||
|
|||
|
Consider using shared or dynamically linked libraries (.DLL in Windows, .so on *nix). Most programming languages provide support for calling system functions and the interface to those is usually implemented via shared libraries of some kind.
So for Java for instance, there's probably some keywords you can use to define a function with "C" or "Pascal" calling conventions. You'd have to write a special header or interface file for each language that maps the function name to your DLL. So instead of creating .LIB files, you need to compile .DLL or .so files and then investigate how to interface to those from each of the target languages. You may need to have multiple versions of your DLL/SO files to support different function calling conventions. Any good C/C++ compiler can generate both standard C and Pascal calling conventions.
__________________
It's not always a matter of what you can do with a language, but whether you should. [JwD] |
|
#4
|
|||
|
|||
|
Thanks jwdonahue and DevCoach for your responses.
I will investigate creating the necessary .SO's for the specific languages and will post the information back here when I get it completed. |
|
#5
|
|||
|
|||
|
Quote:
No they don't - in general only languages that compile down to machine code can be used to make dll/so files. Any interpreted language will have a hard time doing this, including Java, Python, Ruby, Perl, etc. (Yes I know Java is compiled, but it compiles down to bytecodes that are then interpreted. The same is true for Python and probably the others). If you are developing for Windows then your best bet is to create a COM interface that the plugin must provide. Most languages on Windows support COM in some form. I don't think there is a standard Linux equivalent - AFAIK there are a few competing systems such as DCOP and D-Bus. Alternatively you can launch the plugin as a separate process and talk to it using a pipe or via UNIX or IP sockets (which is what COM/DCOP/D-Bus/etc do under the hood). There may be something similar to COM on the Mac - I have no idea. The problem with all of the above is speed - using COM / DCOP etc is much slower than calling a function linked into the same process. Dave Last edited by DevCoach : April 22nd, 2008 at 02:06 AM. |
|
#6
|
|||
|
|||
|
With Java, you can use JNI to talk to your C framework.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > Software Design > Language bindings |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|