• Hi Gordon,

    First of all, thanks for implementing the Espruino engine and the possibilities it may provide for the community.

    I'm considering using the Espruino engine to be embedded into a Ansi-C console application (Open Source project), running on generic Linux.

    I haven't really found any documentation about how this can be done, just trying to get my head around it all by looking sporadically into the sources. So my questions are:

    1. Is it possible to execute JavaScript from within the C-program, and when completed, returning to the C-program?
    2. In the C-program, I'd like to expose variables that the running Javascript can read/update. Is this available?
    3. How to implement new binding functions (calling a C-function from JavaScript).

    With possible answers to these questions, Espruino would ultimately become a low-ressource embeddable JavaScript interpreter as an alternative to the big V8 and Spidermonkey engines.

    Kindest regards
    Gunther

  • Hi Gunther,

    It's probably best if I answer in order:

    1. Yes - just look at targets/linux/main.c to see how this works.

    2. That's more difficult I'm afraid - you can dynamically read the values of variables but you can't yet write them. Of course you could always add getMyVar() and setMyVar(123) functions. The other option is to read the value of the JavaScript variable whenever you want it.

    3. It's probably best to just define your functions with the specially formatted comments in the header, and they'll be added at compile time. See jswrap_*.c to see how it works.

    Having said all that, it might be worth looking at something like duktape instead. Espruino is designed for chips with 8-128kB RAM. As such it's really efficient for them, but if you start to use it for bigger things then it will probably start to show some weaknesses (like in the handling of big arrays).

  • Thank you!

    Duktape seems to be an excellent choice, since I only would want to expose certain API's.

    Warm regards
    Gunther

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

How to embed Espruino in a C-application, then interacting with Espruino

Posted by Avatar for gstrube @gstrube

Actions