3 ms·
I've been waiting a long time for MicroPython to become usable as an embedded script interpreter -- it can't be run asynchronously [1] so scripts can't do waits
by versteegen 4y ago
I've been waiting a long time for MicroPython to become usable as an embedded script interpreter -- it can't be run asynchronously [1] so scripts can't do waits (aside from that, MicroPython is amazingly full-featured). CPython can't either, which is why the Stackless Python fork was created, which is used in games such as EVE Online. But that's far too heavy for my tastes.
So I was hoping that PocketPy could do that, but after looking around I can't find any suggestion it's possible, and the API looks very sparse. I'm very happy to see a new Python interpreter built for embedding, but I can't use it. Maybe it can be added easily enough. Keep it up!
If you want to see a scripting language designed from the ground up for embedding, Lua and Squirrel IMO have the most complete APIs (though not the most efficient or easy to use) [2][3], and LuaJIT has even better lua<->C bridging. I've looked at the APIs of many other small scripting languages, and haven't found any others that can do everything that these can.
[1] https://github.com/micropython/micropython/issues/3619 https://github.com/micropython/micropython/issues/3619
[2] In particular https://www.lua.org/manual/5.4/manual.html#4.5 https://www.lua.org/manual/5.4/manual.html#4.5
[3] http://squirrel-lang.org/squirreldoc/reference/embedding_squirrel.html http://squirrel-lang.org/squirreldoc/reference/embedding_squ...
- Gibbon1 4y agoAfter 40 years of dicking around the C21 has an #embed preprocessor feature. I think which allows you to write stuff like const char python_script_foo [] = { #embed <foo.py.wav> }; Would be useful for embedded scripting. Especially for firmware.
- JonChesterfield 4y agoThis was of course available though inline assembly or code generators from the beginning. So C21 is more complicated for the extra looks-like-prepreprocessor-but-probably-isn't syntax with no increase in expressivity.
- dotancohen 4y agoHow could that not be a preprocessor? Or are you suggesting that the compiled binary will now include a Python interpreter?
- unwind 4y agoIt is a preprocessor directive, the result must be as if the contents of the file were inserted byte by byte as integer literals. See [1] for more information (which, btw, also states that #embed is in C23, not C21 (which doesn't exist as far as I know)). [1]: https://thephd.dev/finally-embed-in-c23 https://thephd.dev/finally-embed-in-c23
- JonChesterfield 4y agoIf it's implemented in the preprocessor - e.g. expanding to a comma delimited char array - then the performance justification for adding it to the compiler is lost. However you might be using "preprocessor directive" in the language semantic phase sense, not in the "preprocessor does it" sense.
- Gibbon1 4y agoIt's inserted as a binary blob by the compiler. So just a simple copy of the file contents.
- dmos62 4y agoHave you ever looked at newLISP [0]? It's been on my radar for a while, but I've not yet had the chance to try it. Its FAQ's [1] item 18 lists a few projects it's been used as an embedded language in. [0] http://www.newlisp.org/ http://www.newlisp.org/ [1] http://www.newlisp.org/index.cgi?FAQ http://www.newlisp.org/index.cgi?FAQ
- versteegen 4y agoThanks, I'll give it a look when I have time. There's certainly a lot of embeddable lisps due to their simplicity, but I've never really given any serious consideration.