Most Read Latest News Blog Resources

The Language of Lua




October 15, 2006 — 
The past several months have seen a lot of ink spilled on the rise of dynamic languages. The reason for this resurgent interest in scripting, I believe, is the confluence of two factors: the speed of today’s hardware and the recovery from what one pundit labeled the “Java nuclear winter.” The latter refers to a phenomenon that has been consistently overlooked in the suddenly chic castigations of Java.

At the time Java was launched, it represented a very substantial step forward from the state of the art, C++. Java’s promise of universal portability and its built-in garbage collection, immutable strings and lack of a preprocessor or conditional compilation were all very different ways of looking at the world that resonated deeply with developers. While these innovations came from other languages, Java was the first mainstream language to bring them all together.

I hasten to add that this was true innovation and Java was embraced by many developers the same way that Ruby is today—as a brilliant alternative to the bloated de facto language of the day. As some veteran readers will surely recall, there was considerable doubt as to whether Java would actually succeed in its core mission: less buggy code and true portability. It was not until Sun worked out the last JVM kinks and Microsoft’s attempt to extend the platform was finally smashed down that we all knew Java had turned the corner and would succeed in its ambitious mission.

That period—the mid-1990s—was a fertile time for the creation of dynamic languages. PHP (released in 1995), Ruby (1995), Lua (1993) and Python slightly earlier are all part of the same generation as Java. And in toto they were a statement about the need for a high-level alternative to C/C++ that would be less narrow than the “little languages” used in Unix (such as awk, sed and shell scripts) and not proprietary like the many 4GLs floating around at the time.

Now that Java has assumed the legacy role played by C++ in those days, developers are looking anew at the alternatives. And with the great advances in hardware diminishing the performance costs, some of those old languages have a new viability. Among the few that have not already been widely adopted, Ruby and Lua stand out. Ruby, as we have discussed earlier, is in the process of crossing the chasm.

Lua, however, remains a lesser-known alternative that has some very nifty features not commonly found elsewhere. The first is performance. In most independent benchmarks, it beats and sometimes routs all other dynamic languages. It is also lightweight. The entire distribution—compiler, runtime and libraries—fits in 1MB. Both aspects are intentional, as the primary application for Lua is as an embedded dynamic language in C/C++ applications. Today, C and C++ are used where performance is essential, and so an embedded language has to have similar benefits. As a result, Lua is very commonly embedded in games (World of Warcraft in particular) and occasionally in ISV offerings (such as Adobe LightRoom).

However, it functions just fine as a stand-alone language. Among its unique capabilities is that its fundamental object is a table (or what many people call hashes or maps). It uses a hash to implement object orientation—a capability made possible by implementing functions as first-class objects. That is, you can stuff a function into a hash slot just as easily as you can stuff an integer. This mechanism is used for closures and for inheritance. Single and multiple inheritance are available by setting up the tables so that any missing functions are looked up in parent tables. Elegant, no? Lua leverages hashes in procedural contexts as well. For example, functions can return hashes, enabling them to return multiple values from a single call.

Of course, Lua has the usual dynamic features such as duck typing, garbage collection (with the capability of tagging elements for collection) and wide portability, as well as an open-source implementation. In addition, Lua benefits from a very active community that has created numerous libraries and development tools. Like Ruby before Rails, Lua is a gem waiting to be discovered—the difference is that it’s much faster than Ruby, has a tiny runtime footprint and is easier to embed. For ISVs, in particular, it represents an important option.

I promise soon to move on from this topic of dynamic languages. I have one more to cover this year: Groovy, the about-to-be-released Java scripting language, which like Lua has numerous innovative features plus complete Java compatibility. Then, back to the larger travails we all face.

Andrew Binstock is the principal analyst at Pacific Data Works.


Share this link: http://www.sdtimes.com/link/29657
 

Add comment


Name*
Email*  
Country     


  • Comment
  • Preview
Loading



 
 
 
 
News on Monday
more>>
SharePoint Tech Report
more>>


   

 
 
Download Current Issue
ISSUE 3/15/2010 PDF

Need Back Issues?
DOWNLOAD HERE

Receive the print Edition?


 
blogs tab
Google Code turns 5
Google Code Turns 5, and adds a Paxos Algorithm to make the system more stable and reliable.
03/17/2010 11:16 AM EST

Test your Visual Studio 2010 know-how
Microsoft is offering free beta certification exams for Visual Studio 2010.
03/17/2010 11:08 AM EST

Microsoft lifts the hood on IE9
Microsoft is previewing IE9.
03/16/2010 01:10 PM EST

 

Events calendar tab
3/22/2010 to 3/25/2010
Santa Clara, Calif.
The Eclipse Foundation

4/12/2010 to 4/14/2010
Las Vegas
Penton Media

4/12/2010 to 4/15/2010
Santa Clara, Calif.
O'Reilly Media

4/19/2010
New York City
Flagg Management

4/25/2010 to 4/28/2010
Overland Park, Kans.
IIUG