Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you make a language binding?

Tags:

binding

Although I do more or less understand what a language binding is, I am struggling to understand how they work. Could anyone explain how do you make a Java binding for WinAPI, for example?

like image 999
qeek Avatar asked May 31 '09 20:05

qeek


People also ask

What is meant by language binding?

Binding generally refers to a mapping of one thing to another. In the context of software libraries, bindings are wrapper libraries that bridge two programming languages, so that a library written for one language can be used in another language.

What type of binding occurs at language?

Static Binding (cont) • At language definition. – Structure of language.

What is language binding in selenium?

The term language binding generally refers to mapping a software library/API to another language in the manner to be used in two different developing ecosystems and/or environments with the same functionalities. The number of Selenium users has grown significantly over time.


2 Answers

You'll find much better results if you search for Foreign Function Interface or FFI. The FFI is what allows you to call functions that were written in a different language, i.e., foreign ones. Different languages and runtimes have vastly different FFIs and you'll have to learn each one individually. Learning an FFI also forces you to know a little more about the internals of your language and its runtime than you are ordinarily used to. Some FFIs make you write code in the target language, like Haskell (where FFI code must be written in Haskell), and others make you write code in the source language, like Python (where FFI code must be written in C).

Certain languages don't use the term FFI (though it would be nice if they did). For Java, it's called Java Native Interface, or JNI.

like image 113
Dietrich Epp Avatar answered Nov 04 '22 14:11

Dietrich Epp


Languages (usually) have defined syntax for calling "native" code. So if you have library that exports method foo(), making a biding would mean that you will create, in you example, Java class with method foo(). That way, you can call MyBinding.foo() from the rest of a code, it will make no difference whether it was pure Java method or compiled C code.

Again for Java, you probably want to look at JNI documentation. Other languages have similar mechanisms. There are tools like SIP that will take bunch of C(++) header files, and produce Python bindings for it. I guess other languages could have similar tools as well.

like image 20
Slartibartfast Avatar answered Nov 04 '22 15:11

Slartibartfast