10 Reasons Why You Should Make Lua (A New Programming Language) Your Coding Friend - A Detailed Review

By Angsuman Chakraborty, Gaea News Network
Friday, December 26, 2008

Amongst all the technologies and well established programming languages like Java, Ruby and etc. we often forget to look into the world of new kids on the programming block. Lua is one such aspirant. Lua (pronounced LOO-ah) means moon in Portuguese. It is a powerful, fast, light-weight, embeddable scripting language which combines simple procedural syntax with powerful data description constructs. This is 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.Besides having all the features, Lua is extremely robust, imperative and reflective too. Lua’s fair share of limelight is claimed at the video games industry.

Lua was created in 1993 by Roberto Ierusalimschy, Luiz Henrique de Figueiredo, and Waldemar Celes, members of the Computer Graphics Technology Group (Tecgraf) at PUC-Rio, the Pontifical University of Rio de Janeiro, in Brazil.

Features

1. Lua is Tuned to Be Fast

Independent benchmarks show that Lua is often amongst the fastest interpreted dynamic languages. The Lua interpreter has been extensively tuned for high performance. The call-out mechanism to C is one of the fastest, too (compare to JNI).

The integration of other fast compilers give Lua the edge to be faster and more preferable for cell phones than other relatively resource hungry PLs.

2.  Lua is small

The Lua interpreter easily fits in under 100 kilobytes including the base libraries. You can not expect that from other larger runtimes like Java or Python where, to strip a non-essential part of a code is either impossible or very tough than to ignore it. Minimal memory cache is something that Lua uses to good effect for mobile phones and smartphones of today’s generation.

3.  Extending Lua is Easy

Lua has been designed to work together  with C. The Lua VM offers a small, yet flexible C API. Even beginners can write a binding in minutes without studying huge manuals. There are plenty of automatic
binding generators for larger tasks, too. Compared to other language’s binding mechanisms, Lua’s C API effectively provides a shield between the internals of the Lua VM and the outer world.

4. Embedding Lua

Lua is a fast language engine with small footprint that you can embed easily into your application. Lua has a simple and well documented API that allows strong integration with code written in other languages. It is easy to extend Lua with libraries written in other languages. It is also easy to extend programs written in other languages with Lua. Lua has been used to extend programs written not only in C and C++, but also in Java, C#, Smalltalk, Fortran, Ada, and even in other scripting languages, such as Perl and Ruby.

5. Lua is portable

Lua is distributed in a small package and builds out-of-the-box in all platforms that have an ANSI/ISO C compiler. Lua runs on all flavors of Unix and Windows, and also on mobile devices (such as handheld computers and cell phones that use BREW, Symbian, Pocket PC, etc.) and embedded microprocessors (such as ARM and Rabbit) for applications like Lego MindStorms.

6. Lua has coroutines

Multitasking is desirable, even on small devices. Too often one encounters annoying limits on cell phones, e.g. one cannot open the calendar or lookup a number in the phonebook while on the phone with someone. But fully preemptive multitasking is either not supported or is considered too costly for these environments.

Lua’s coroutines provide a fast and memory efficient way for non-preemptive multitasking. Lua’s coroutines are built-in and are independent of the capabilities of the underlying OS. Lua
even happily runs on devices without an MMU.

7. Lua can be sandboxed

it’s easy to restrict access to library functions on a function-by-function basis. Memory use as well
as CPU usage can be restricted, too. This is very important for a cell phone environment. Removing certain dangerous library functions or (better yet)  just offering a handful of “safe” functions for use by
user-written applications is easy. It’s even possible to manage multiple protection domains with different privilege levels in the same Lua VM.

Other VMs provide either no support for sandboxing (short of completely ripping out huge parts of their libraries) or offer only complicated and inflexible protection mechanisms. Lua can be sandboxed _in_ Lua and with standard Lua calls, providing for maximum flexibility at minimum cost.

8. Lua is malleable

Lua has just enough syntactic sugar and meta-mechanisms to be easily repurposed for domain specific
languages (DSL).

9. Lua is Well Documented

A good programming language needs to be well docuemented to be read and understood. Lua has put it perfectly into effect. It has a simplistic website that holds all the necessary information from FAQ to download guide. It is pretty transparent.

10. Lua is Free and Simple

Lua is free software, distributed under a very liberal license (the well-known MIT license). It can be used for any purpose, including commercial purposes, at absolutely no cost. Just download it and use it.

Lua has a simple, yet powerful syntax which fits on a single page. The semantics are  consistent and intuitive. Beginners can start to program right away. Teaching Lua is  easy, excellent programming books are available. No huge and expensive IDEs and SDKs are needed, any text editor will do.

See the normal factorial program can be written like this through Lua.

function factorial2(n)             -- Shorter equivalent of the above
  return n==0 and 1 or n*factorial2(n - 1)
end

Lua also has advanced features like closures, coroutines, meta-mechanism and lots of finely tuned details. All of these make it attractive for professional developers, too. But none
of these features get in the way of beginners.

The WoW Lua add-ons are a good example of the power of an open and collaborative environment. It nicely shows what a huge driving factor user contributed (active) content can be for the success of a project.

If you want to quickly gain a huge library of gadgets and add-ons for your cell phone, then Lua is the way to go.

Why not Python then?

Python is a popular programming language. Both Python and Lua are commonly embedded in applications to provide scripting support. So why not go for the more popular one? Python is better equipped, has a remote debugger and loadsa features which Lua don’t.

Well if you are looking for a smaller, easier programming language which does the work as good as Python can, then why not go for Lua? Lua has a powerful library, a strong and simple syntax and etc. I will at least suggest you to try Lua once.For more comparisons, you can read their own article on how lua fairs better than others

Conclusion

In this world of all the programming languages, Lua is starting to make a mark. If you are mobile widget developer or a game programmer, then Lua can prove to be ideal. Give it a try.

[Thanks to Mike Pall, the programmer who built LuaJIT]

Discussion

agard
June 7, 2010: 9:16 am

“For more comparisons, you can read their own article on how lua fairs better than others”
You mean ‘fares’, as in, see how it goes, like a taxi fare. Not fair, which makes no sense, and is not a verb.


Kamil
September 30, 2009: 7:36 am

Point 2 has a bug ;p
Size of Java Micro Edition for mobile devices is less than 100 kilobytes. Bigger than LUA interpreter is Java Standard Edition, but is only used in desktop solutions.
But Java is a programming language, not designed for scripting.

YOUR VIEW POINT
NAME : (REQUIRED)
MAIL : (REQUIRED)
will not be displayed
WEBSITE : (OPTIONAL)
YOUR
COMMENT :