ParTcl
This post is part 2 of the arduino-scripting series:
C headers are annoying. I was getting fed up with uLisp and so I decided to run another Google search for “embeddable scripting language for Arduino”.
It turned up mruby-arduino – poorly documented, and a little too big for my needs.
It turned up eLua – which unfortunately is just a flashable firmware with no C interface for custom functions (just like with MicroPython).
And it turned up Serge Zaitsev’s ParTcl interpreter. It’s a bare-bones interpreter for the Tcl programming language which implements only 5 core functions (subst
, set
, while
, if
, and proc
) as well as puts
and some math functions.
Despite this minimalism, it is simple to understand as most things are abstracted away into functions and datatypes – and, leveraging the fact that “everything in Tcl is a string,” malloc
and free
can be used easily for dynamic memory management.
Additionally, from the Github readme:
- Can be extended with custom Tcl commands
- Runs well on bare metal embedded MCUs (~10k of flash is required)
…which is exactly what I need to use it as an Arduino library!
There are a few bugs – namely this one:
In the default implementation lists are implemented as raw strings that add some escaping (braces) around each item. It’s a simple solution that also reduces the code, but in some exotic cases the escaping can become wrong and invalid results will be returned.
Using my experience from Lisp lists, I saw that Tcl lists could be implemented as a linked list as well. I proposed it and we’ll see what Serge says. I could probably fork ParTcl and add it myself anyway.
This seems like the best solution so far, and what I’ll probably go with.
One last thing, with the regard to the name – do you think ParTcl would run on a Particle?
Related Posts