Earlier I told you about Carambola, the small and inexpensive embedded Linux board, and how it’s going to be the brains of the Stripe internet-enabled linear clock. To make an interactive product do what you want you need software to tell it what to do. There are many programming and scripting languages around, so how do you pick the right one? In this blog post I’ll show you how I settled for Lua as the scripting language of choice for Stripe.
Programs and scripts
When choosing a language it is important to distinguish between programming languages and scripting languages. With programming languages such as (Arduino) C or C++ you write your program in a text editor or IDE, compile it into native machine code using a compiler and finally run it. If you want to use the program on a different operating system (Mac, Linux or Windows) or on a different platform (a normal pc based on i386, a smartphone with an ARM processor or the Carambola using MIPS) you need to go back to your development computer and recompile the program for the right platform.
Scripts, on the other hand, start out as text files just like with a programming language. However, they do not need to be compiled beforehand. The final platform turns the script into machine code while you run the script. This makes it possible to use the same script on different platforms, and also makes it easy to make small changes to the script without having to go back to your development computer. This makes scripts a lot easier to work with, but it does come at a price: speed. The extra translation step from script to native machine code makes a script run slower than a compiled program.
Picking the right language
Prime candidate: Python
A very popular scripting language is Python. It’s powerful, fast, has a large number of users and therefore a large number of tutorials. The tutorials and documentation are riddled with Monty Python references, which make following them quite entertaining. Libraries for Google Calendar and CalDAV exist, just like numerous others. For an embedded device, however, there is one big gripe. The full Python installation on Carambola is about 5MB, which is a lot on a device that has only 8MB of flash. Adding libraries quickly makes you run out of space – the required libraries for the Google Calendar library would add up to about 14MB!
Lua to the rescue
Like Python, Lua is fast and powerful. But it is also lightweight – meaning it doesn’t take much space and resources to run. It’s often used in games such as World of Warcraft and Angry Birds because it’s fast and easily integrates with other programming languages. Moreover, the configuration interface for OpenWrt (the Linux-flavor used by the Carambola) is partly written in Lua which makes it very easy to adjust system settings such as time zone and IP addresses.
(And if you’re curious: all Lua files I need for Google Calendar integration use up 140kB of disk space. That’s 100 times less than with Python.)