Can I still code in C, but use Espruino as a JS interpriter? #5733
Replies: 1 comment
-
Posted at 2017-03-24 by oesterle 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 Some of that is documented here: I'd also suggest taking a look at the C source of Espruino's built-in libraries, like Math, to see actually working examples. Posted at 2017-03-24 by @gfwilliams 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 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. Posted at 2017-03-24 by user75010 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. Posted at 2017-03-24 by @gfwilliams 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. Posted at 2017-03-25 by oesterle @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 Posted at 2017-03-26 by user75010 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 |
Beta Was this translation helpful? Give feedback.
-
Posted at 2017-03-23 by user75010
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?
Beta Was this translation helpful? Give feedback.
All reactions