Software Design
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreSoftware Design

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old April 18th, 2008, 02:39 PM
Thoku Thoku is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 175 Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 2 h 6 m 45 sec
Reputation Power: 14
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.

Reply With Quote
  #2  
Old April 19th, 2008, 03:32 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,224 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 23 h 4 m 39 sec
Reputation Power: 263
Take a look at SWIG.
Quote:
SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby. The list of supported languages also includes non-scripting languages such as C#, Common Lisp (CLISP, Allegro CL, CFFI, UFFI), Java, Lua, Modula-3, OCAML, Octave and R. Also several interpreted and compiled Scheme implementations (Guile, MzScheme, Chicken) are supported. SWIG is most commonly used to create high-level interpreted or compiled programming environments, user interfaces, and as a tool for testing and prototyping C/C++ software. SWIG can also export its parse tree in the form of XML and Lisp s-expressions. SWIG may be freely used, distributed, and modified for commercial and non-commercial use.


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

Reply With Quote
  #3  
Old April 19th, 2008, 04:06 PM
jwdonahue jwdonahue is offline
Bellevue WA, USA
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2004
Location: Bellevue Washington, USA
Posts: 1,038 jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level)jwdonahue User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 6 Days 23 h 14 m 51 sec
Reputation Power: 66
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.
Comments on this post
Thoku agrees: Thanks, really useful
__________________
It's not always a matter of what you can do with a language, but whether you should. [JwD]

Reply With Quote
  #4  
Old April 20th, 2008, 02:07 PM
Thoku Thoku is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 175 Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level)Thoku User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 2 h 6 m 45 sec
Reputation Power: 14
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.

Reply With Quote
  #5  
Old April 20th, 2008, 04:37 PM
DevCoach DevCoach is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: Feb 2004
Location: London, England
Posts: 1,224 DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level)DevCoach User rank is Captain (20000 - 30000 Reputation Level) 
Time spent in forums: 1 Week 5 Days 23 h 4 m 39 sec
Reputation Power: 263
Quote:
Originally Posted by jwdonahue
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.


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.

Reply With Quote
  #6  
Old April 21st, 2008, 10:45 PM
imchi imchi is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Posts: 129 imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level)imchi User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 20 h 45 m 55 sec
Reputation Power: 20
With Java, you can use JNI to talk to your C framework.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreSoftware Design > Language bindings


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT