Search code examples
javascriptcwebkitjava-native-interface

Accessing native c functions from javascript


I have a javascript application which will be running on an embedded platform. It has to call some c APIs which are already implemented in the platform. This is a proprietary application and is meant to run only on selected devices.
I am running this application on webkit. There is no JVM available.
I am thinking of some options and got a few. I would like to know whether any of them are applicable or a better option. I am new to javascript so my ideas may not be right.

  1. Something similar to JNI ( if this exists at all)

  2. Develop a plugin for webkit which exposes some Javascript APIs to the application and then calls native c functions

  3. Modify webkit


Solution

  • Your 2nd suggestion is pretty close to what you need to do. When you compile the browser (you don't need to compile webkit yourself) you can register functions and objects.

    If you are using Qt, you should probably start here.

    If you are using GTK, the registration is different, here is a nice example.