
Porting Lua, TinyJS and Webkit - An Interview with Mikael Kindborg
Published by Chris Hughes on August 17, 2010Mikael Kindborg is well known in the dynamic languages and Smalltalk communities. He's a former lecturer in Computer Science at Linköping University, and he's been working recently with porting Lua, TinyJS and WebKit to MoSync. I took the opportunity of a break in his busy schedule to ask him about this work.
Chris: Can you tell us a little about Lua, TinyJS and WebKit, Mikael?
Mikael: Lua is a nice compact language suitable for mobile devices, while TinyJS is a very small subset of JavaScript.
TinyJS is slower than Lua, but it is useful for applications that need a JavaScript-like script engine. It is possible to alter the TinyJS interpeter to fit your needs.
WebKit is a web browser that is becoming the standard for mobile platforms. By making MoSync talk to WekKit it is possibile to build mobile applications in HTML and JavaScript that can call any service that is available in MoSync.
And are they all open source?
Yes, all three are open source.
Lua is a well-established language. Its memory requirement is very low and its performance is the fastest among interpreted languages.
With WebKit, what you can do depends on the programming interface implemented by the mobile OS vendor. Android and iPhone, for instance, have different means of interfacing with WekKit. The great thing with MoSync is that these differences are abstracted away, so that the programmer can use one uniform interface to WebKit.
Are these languages related to one another? How would you use them?
Lua, TinyJS and WebKit serve different needs. Lua is the prime choice if you want a great scripting language for your application. If you need something that is also small, is similar to JavaScript, and performance is not of highest importance, then TinyJS is an option. For building advanced applications using JavaScript as the primary programming language, WebKit is the way to go.
Can you give us some examples of the types of applications you can easily build with Lua, TinyJS and Webkit?
WebKit enables all kinds of web applications. The look and feel for the user interface of a web application is very flexible, which makes it suitable for applications that needs a unique graphical look. WebKit also enables porting desktop web applications to mobile devices.
Lua is great for applications that can benefit from a scripting engine. Many games use Lua to script the logic of the game. Business applications could do the same thing. The big advantage of using a scripting language is that it is quick to try things out, and quick to modify existing software. For example, if business rules in the application logic needs to be changed, that is easy to do by editing a Lua script. Furthermore, end-users could potentially author applications using Lua and high-level easy to learn libraries.
TinyJS could be used for the same purposes as Lua, but keep in mind that it is much less widespread and supported compared to Lua and JavaScript in WebKit.
Can you show us some code?
This is the Lua source code for a simple painting application. The event handler functions get called from MoSync. OnInit paints a white background. OnTouchDown, which is called when the user touches the screen, paints a tiny black square. OnTouchDrag is called when the user moves across the screen, and it simply calls OnTouchDown to paint more black squares.
function OnInit() SetColor(255, 255, 255) FillRect(0, 0, ScreenWidth(), ScreenHeight()) end function OnTouchDown(x, y) SetColor(0, 0, 0) FillRect(x - 5, y - 5, 10, 10) end function OnTouchDrag(x, y) OnTouchDown(x, y) end
What does this program look like when using it?
Here is an example:

As a mobile application developer, what do I need to do to start playing with Lua, TinyJS, and Webkit on MoSync? Do I need to download stuff from somewhere? How do I bootstrap myself?
Download MoSync, then go read http://code.google.com/p/mobilelua/wiki/DynamicLanguagesOnMobileDevices, then try out Lua and/or TinyJS.
For WebKit on MoSync you will have to wait for a while - it is still indevelopment! If you are interested, you can follow, and participate in, the development in this Subversion repository: http://code.google.com/p/mosync/source/browse/#svn/MoSync/branches/webkit.
Thanks for you time, Mikael.
Share on Facebook