My favorites | Sign in
Project Home Downloads Wiki Issues Source
Search
for
DynamicLanguagesOnMobileDevices  
Simplified development on mobile devices using dynamic languages
Updated May 20, 2011 by mikael.k...@gmail.com

Introduction

Developing mobile applications can be a rough ride. The number of platforms is staggering and the programming langauges and development tools are often quite demanding to learn and master. The use of dynamic languages like Lua and JavaScript can change this picture.

MoSync is a C/C++ cross-platform mobile development tool, which produces binaries for a wide range of mobile operating systems. The nice thing with C/C++ is the ability to port interpeters for dynamic languages to mobile platforms. In the case of MoSync, this means that an interpreter that runs on MoSync will run on every platform MoSync supports.

MobileLua is a port of the Lua programming language Lua that runs on MoSync. This enables using a fully featured dynamic language to script mobile applications.

Motivation

One reason for using a dynamic language is the ability to evaluate code at runtime. With this comes a lot of interesting applications, for example:

  • Dynamically publish and load applications over the Internet
  • Develop applications right on the device
  • User scripting and user-created applications

Another reason is simplified syntax and high-level language constructs, things that can benefit both beginning programmers and professional developers.

To create mobile applications you typically need to download and install the development tools for the platforms you want to develop on (e.g. Android, Symbian, BlackBerry, iPhone), and usually code in a static language such as Java. Developing in a static language usually involves some kind of build process; edit code, compile, launch the application, and test the application. With a dynamic language this process can be simplified, since new code can be dynamically loaded into a running application.

With an application that embeds an interpreter and the ability to dynamically load code, programming could be done by publishing scripts on the Internet (using any text editor and upload tool) and download them to the device. No need for complex development environments. Support for debugging is of cource needed, and there are ways of doing that.

Restrictions on iPhone/iPad

The catch on iPhone/iPad is that you are not allowed to dynamically download and run interpreted code. But it seems to be fine with Apple to use a scripting language internally in an app, see e.g.:

This means that you can benefit from using a dynamic language for development and then package your program as a native application and deploy it on the AppStore.

Example program

The following is an example of a very simple painting program in Lua:

-- MOBILELUA BEGIN

-- PaintDemoBasic.lua
-- Author: Mikael Kindborg
-- Date: 2011-02-23
-- Description: Simple paint program demo. Supports multi-touch!

-- Fill background.
Screen.setColor(255, 255, 255)
Screen.fillRect(0, 0, Screen.getWidth(), Screen.getHeight())
Screen.update()

function Paint(x, y, touchId)
  if touchId == 0 then 
    Screen.setColor(0, 0, 0) 
  else
    Screen.setColor(0, 200, 0) 
  end
  Screen.fillRect(x - 20, y - 20, 40, 40)
  Screen.update()
end

System.onTouchDown(Paint)
System.onTouchDrag(Paint)

-- MOBILELUA END

The Paint function is used as an event callback function which is called when the user touches the screen to paint.

Screenshot of this program in action:

Overview of the API

The API MobileLua uses to access MoSync functionality is currently under development. Documentation is underway, and you are most welcome give feedback and participate in the MobileLua project.

Notes

MoSync supports a subset of full C/C++, and exception handling is not (yet) supported. The port of Lua therefore uses conditional code to handle some special cases, especially for error handling.

Compile with flag MOSYNC set (compiler switch -DMOSYNC). This is already set in the MoSync project Eclipse settings included with the download.

Contact

Your feedback is most welcome, please contact us if you have questions and/or suggestions.

Email: mikael.kindborg@mosync.com

MoSync home page: http://www.mosync.com


Sign in to add a comment
Powered by Google Project Hosting