Exploring Lua via Corona SDK


Last year I learned Lua as a new programming language. I got interested mainly due to its use as the primary programming language of the Corona SDK but also due to its use on other projects. Lua is used in World of Warcraft, Angry Birds, Adobe Lightroom and widely used within the gaming industry as a scripting engine atop a lower level 2d/3d graphics engine like OpenGL. Here is the basics from Lua.org:

Lua is a powerful, fast, lightweight, embeddable scripting language.


Lua combines simple procedural syntax with powerful data description constructs based on associative arrays and extensible semantics. Lua is dynamically typed, runs by interpreting bytecode for a register-based virtual machine, and has automatic memory management with incremental garbage collection, making it ideal for configuration, scripting, and rapid prototyping.

Corona SDK provides a 2d graphics API using OpenGL ES combined with Lua for building applications targeting iOS ( iPad & iPhone), Android phones, and Android tablets like NOOKcolor (Android 2.1 API7). The SDK has evolved with developer feedback to include many native device features (accelerometer/camera/webview) combined with fully hardware accelerated graphics/text and integrated with APIs for including physics (Box2d) and social (Facebook/OpenFeint). Long story short is that it is a great SDK for creating graphical interactive applications and games. Productivity is where Corona
and Lua really shine. Here are some code to get you thinking:
Create a new image and add to displaylist:

myImage = display.newImage( "image.png")

Draw a square and place it within a group:

local rect = display.newRect(0, 0, 100,100) 
rect:setFillColor(140, 140, 140) 
local group = display.newGroup() group:insert( rect )

Create some images and apply physics to them:

local physics = require( "physics" )
physics.start()
local sky = display.newImage( "bkg_clouds.png" )
sky.x = 160; sky.y = 195
local ground = display.newImage( "ground.png" )
ground.x = 160; ground.y = 445
physics.addBody( ground, "static", { friction=0.5, bounce=0.3 } )
local crate = display.newImage( "crate.png" )
crate.x = 180; crate.y = -50; crate.rotation = 5
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0.3 } )

NOOKcolor and Corona SDK work great together. On Android, Corona is built atop the NDK (Native Development Kit) with graphics rendered to either OpenGL ES
1.1 or 2.0 depending on device support. NOOKcolor ships with a great GPU supporting both OpenGL ES 1.1 & 2.0 and thus graphics performance really shines. Corona SDK makes building more reading centric applications and games easy targeting NOOKcolor and provides for a solid foundation for cross-device development. As part of my internal work I am building a photo viewer for NOOKcolor with Corona SDK that can import from Flickr and other image services. The SDK makes quick work of this task given the pliability of Lua as a language. As a language is a a close kin to silly putty and executes very fast. At first it feels like Flash 5 ActionScript 1 but slowly you will find a subtle quality that makes writing Lua very enjoyable. I strongly suggest you take a look at Lua and Corona SDK, the language and toolset are a great to learn, know, and apply to your next project.

Cheers,

Ted :)

3 thoughts on “Exploring Lua via Corona SDK

  1. Steven Diomampo

    Hey Ted,

    I’m just scratching the surface with Lua using Corona SDK and find it fits well for Flash minded folks (myself included). Do you have any suggested IDE’s or plugins for development? What’s your dev environment like? I’m on an Mac running TextWrangler at the moment, but keep finding myself waiting for my code hints to popup…thinking maybe TextMate is the way to go after seeing a bundle for it?

    Reply

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s