by SlowRobotAhead · 7y ago · 0 comments
Not exactly backend but that kinda fits my use case. I have a C embedded application that I need scripting on. Nothing unsecure from the user, from my own backend, but it requires a foreign function interface, and its a super constrained device.
Lua, JavaScript, forth, etc. None I’ve been able to find anything I like under 50 kB flash or are even slightly “friendly”.
Found one in JavaScript was close, but it’s an interpreted language which means every letter of code is a byte I need to transfer then have parsed.
I’ll look into this. Esp if it’s still possible to send just bytecode in.
I think you’re right that Lua is the way to go. But I have yet to see someone package it nicely for gcc and to be included and built from an MCU IDE (Keil, Segger Emebbeded, IAR, etc). I’ll keep looking.
https://gist.github.com/Vesnica/3672425
It loads and runs a Lua source code file which calls the exported C function. Lua compiles the source code into byte code before running it but that can also be done ahead of time with the Lua compiler:
https://www.lua.org/manual/5.3/luac.html
It can also be done manually with the dump and load functions:
A typical JavaScript system first compiles the JS source code into bytecode. Then it starts executing (interpreting) the bytecode.
If there is a JIT, that is a second compiler. It monitors the execution of the bytecode to find hot spots where it compiles the bytecode into machine language.