Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
9 years, 8 months ago.
Scripting language
Many of the mbed enabled boards these days have plenty of RAM and ROM - enough to support a basic scripting language. The purpose of this would be to allow some degree of control of my software after flashing (and even some degree of direct development on the board itself). For example the highest level logic of my program could exist in the scripting language, which I could communicate to the devices later to update some of the functionality in-place.
I've created a few scripting languages and interpreters in the past, and what I have in mind would consist of two modules: The parser. The bytecode interpreter.
The language syntax would be extremely basic, IE something like BASIC, to keep the parser as simple as possible. The parser normally wouldn't be included in the device software, unless you literally wanted to connect a keyboard and allow development on the device itself.
The host program would expose whatever APIs to the scripting language that it would need. For example if you have a temperature sensor, then the C code would expose an API like "readTemp" to the scripting language. The implementation for readTemp in C would actually poll the sensor and calculate the value, so the scripting language could then make use of the data. It would be up to the developer to decide how high or low level they want the scripting language to function at. For me personally I would use the scripting language for very high level stuff. For example, I'm using a 128x160 color LCD for output, and I'd like to be able to tweak the layout and formatting dynamically without having to recompile and flash, so that would be an ideal use for a simple scripting language.
Does anything like this exist already, so I don't reinvent the wheel?
1 Answer
9 years, 8 months ago.
There is the Espruino, which also runs on the Nucleo F401, and uses javascript using a custom intepreter. However that immediatly shows the issue with a low-level script based program: Depending on how much you comment your code (so you actually should put as little comments as possible in your functions) it can toggle a pin at roughly 3.5kHz. Which is obviously absolutely horrible and why you should never use javascript on an MCU.
For the very high level stuff it could work, but then you have to make the decission what needs to be scripted and what not. If you just want to move some stuff around on a display you can make any kind of interface where you can modify the layout. (Serial, or via a filesystem, etc). Something you might also have a look at is RPC: http://developer.mbed.org/cookbook/Interfacing-Using-RPC
I just built Lua and it is working well inside of mbed. This is just Lua the language, not that eLua thing. Right now it's around 100k executable, but that includes debugging and IO libraries and the like that can all be stripped out. It also includes the parser which can also be removed if it to just run bytecode.
I'll do a test to see how many times I can strobe and LED in a second.
posted by 29 Nov 2014