• If I wanted to develop a puck.js project in C using Keil, but add in Espruino as a way to dynamically load into ram then run js code then jump back to C, is that possible with the binaries being used right now?

    Examples?

  • Not sure. But I know the converse is possible: you can write libraries in C, and expose methods as JavaScript objects and functions.

    When you build Espruino, the build scripts scan your C code for /*JSON{… comments, in which you describe the mapping between C and JavaScript.

    Some of that is documented here:
    github.com/espruino/Espruino/blo­b/master/libs/README.md

    I'd also suggest taking a look at the C source of Espruino's built-in libraries, like Math, to see actually working examples.

  • At the moment about the best you could do is write a library as @oesterle suggests and then add your code to run in the main loop on an idle handler - and you probably want to compile with GCC and a Makefile too since it needs a few Python scripts to precalculate tables.

    Espruino ends up being quite tightly integrated to the MCU - handling sleep, interrupts, and having its own IO queues - it's basically a mini OS. While with some work could compile it to run under something else, suddenly you'd miss out on all the power saving, bluetooth, GPIO, etc.

    There have been questions about that in the past, and it could be done - however there's very little incentive for me to put effort into making it easy to do since it's not likely to sell any more Espruino boards. I imagine by far the biggest interest would be from people using it on their own hardware.

  • I see, too high level than to just start up the interpreter in a C environment. Ok.

    I look at it the opposite way, that there is a serious lack of lightweight interpretive languages for embedded projects. I already know C is where production products are, but maybe I want to write some test scenarios or execute a remote script using JS. Too bad.

  • There are actually a bunch of 'small' (for various definitions of small) JS interpreters that are just the interpreter if you wanted to use them: Duktape, JerryScript, TinyJS (which isn't really 'proper' JS), v7, and probably others.

    What makes Espruino more useful is that it isn't just the interpreter though - you get the whole API to access the hardware, and for that to really work it does have to have access to the whole device.

  • @user75010, If you are just talking test, you can instrument your C code with something like a very lightweight serial command line. For example, CmdMessenger is an Arduino C++ library that enables you to exercise compiled C(++) functions (with or without arguments) via serial connection. CmdMessenger on GitHub

  • @Gordon

    Thanks for that! Turns out that while Espriuno wasn't what I was looking for V7 and some other Cesanta stuff might be. Really, saved me a TON of time.

    I'll keep Esriuno in mind for future projects that aren't so C heavy.

    @oesterle
    Also thanks, but I wasn't specific enough. I need access to C functions and some basic logic and math. But good suggestion anyhow.

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

Can I still code in C, but use Espruino as a JS interpriter?

Posted by Avatar for user75010 @user75010

Actions