Monday, June 9, 2008

Lua

Lua  is one of my favorites languages (Ruby being #1). For those who do not know Lua, I would describe it as a small language. Small meaning easy to learn, easy to embed and easy to extend; but still a very powerful language.

Some time ago, I used it at work. I work for a mobile phone company and the idea was to introduce widgets to the mobile world. My idea was to use Lua as the language to implement the widgets on the 2 low-end platforms we were using (Infineon  ULC2 and TI Locosto).
Integration of the language itself on the 2 platforms went extremely smoothly. We encountered a few issues on Infineon's because it does not support floating-point. Otherwise, it was integrated in a week or so.
Then, we started extending the language to call the features of the platform. We defined some API to access phonebook, send SMS, call a number as well provide display for text, images...
In the end (to our own surprise :-) ), we quickly managed to design widgets that could run perfectly on both platforms.
The project did not make it in a final product, but our proof of concept showed cross-platforms widgets were possible on low-end platforms by using Lua.

I believe the future of MMI development in the mobile phone industry is scripting, even if C and C++ are currently the leading languages. I noticed that Openmoko is pushing Python and I think they are completely right. There is no reason why a mobile phone MMI can not be written with languages such as Python, Lua, Perl or Ruby.

The only limitation I can think of is the final size of your software. Our widgets source code quickly ended up taking
a few kBytes as soon as we defined a proper MMI. It is clearly an issue to take into account if you are low on space.
We tried to compile the Lua scripts but the final size of the compiled script was often larger than the original script. One obvious solution is to compress the original script. It should work quite well as the scripts are plain text. However it is quite a burden to have to decompress the scripts on the fly.
If you have some suggestions on this issue, I'd be pleased to read them.

If you look for a small language that you want to embed in an application or a low-end chip to run scripts, Lua is a great solution. You can get results in a matter of weeks and given that it is a very powerful language, you will be able to go almost as far as you want.