A Look at Lua
Lua is a free and open-source multi-paradigm programming language released under the MIT license. Created in 1993 by Roberto Lerusalimschy, Luiz Henrique de Figueiredo and Waldemar Celes, Lua is a dynamically typed language. Extremely compact (only 150KB compiled), it is primarily used as a scripting language or an extension to another language (mainly C/C++).
Lua is implemented as a library and has no “main” program. It works only when embedded in a host client. The interpreter is a C program that uses the Lua library to offer a standalone Lua interpreter. Rather than provide a complex and rigid specification for a single paradigm, Lua is intended to be extended to fit different problem types.
Being small, Lua fits on many host platforms and has been ported and used in video games for both the PlayStation Portable and the Nintendo DS, and it is used in larger games, such as FarCry and World of Warcraft. The Adobe Photoshop Lightroom photography program and the lighthttpd Web server have incorporated Lua as well. Lua has a few advanced features, primarily coercion, coroutines, garbage collection, first-class functions and dynamic module loading. Because Lua is small, it includes only a few data types. It attempts to maintain a balance between power and small size.
Lua is comparably as easy as Python in terms of learning how to write code. Of the two, Lua is usually the better choice for embedded systems, simply because it's smaller. Lua's strength is in processing strings and tables. It handles logical equations more adeptly than Python.
For a quick hack, a Lua programmer can process complicated data more quickly and easily than a Python programmer can (although a Ruby programmer can do so almost as quickly). But, for a large application that handles many chunks of complex data, a heavier language such as Ruby or Python may be a better choice.
There is no need to worry about different types of integers. You may have found that the different types of integers and numbers (such as floats, longs or doubles) can screw up the output of your program or even make it crash if you are absent-minded. Lua uses coercion for every integer and number type to convert it into a single type. You can add a float, long integer or a double to any other type of integer or number without a hitch in Lua. In contrast, doing this can cause programs written in Python 2.4 or older versions to crash. Lua is extremely forgiving syntactically. What if, for some reason, you are programming on an embedded device with a four-inch wide screen? You can reduce the amount of lines and other characters, which in turn enables easy reading of the code to make up for the small screen.
Small is beautiful. A programmer can embed Lua into several other languages, such as C/C++ and Java, without bloating the host language, because Lua has a tiny API. Similar to Lisp's single data structure, tables are the only data structuring mechanism that Lua has. This makes tables very powerful, because with a little work, they can emulate data structures in larger languages.
Object-oriented programming implementation is minimalistic. Lua uses tables and functions rather than classes.
In contrast to Python, Lua does not focus on 100% backward compatibility. Many newer releases of Lua break programs written in previous versions. Fortunately, the Lua developers always announce what the new versions of Lua will break.
Lua supports threading. Multiple Lua interpreters can coexist in the same process, and each one can run independently in its own thread. This often makes Lua desirable for multithreaded programs in embedded systems.
To compile and install Lua from the source code, grab a copy of Lua 5.1 from the Lua.org Web site, and untar, configure, make and install it:
tar -xvzf lua-5.1.1.tar.gz cd lua-5.1.1 make xyz make xyz install
(xyz is your platform name.)
Lua should now be installed and working. To test your install, type lua on the command line. An interactive interpreter should appear.
Lua is a dynamically typed language whose syntax is very similar to that of Python and even more similar to Ruby. Line breaks do not play any role in Lua's syntax, like that of Python or Ruby. Take, for example, the following ugly, but valid code:
foo = 89 bar = foo+2 print(bar)
Because it is small, Lua has only eight basic data types:
nil (similar to Python's None)
booleans
numbers
strings
functions
userdata (a type that allows arbitrary C data to be stored in Lua variables)
threads
tables
Lua supports only a few data structures, including arrays, lists and hash tables.
The table type implements an associative array that can be indexed with any value (similar to Python), except nil (dissimilar to Python). Nil's goal is to be different from any other value, as well as the default value for global variables. Nil also plays a much more important role in Lua than None does in Python. Although tables are the only data structuring mechanism in Lua (which may seem like a disadvantage), the table is just as powerful as Python's dictionary and list, and it's even as powerful as Ruby's hash. Tables are used to represent many different types of arrays, sets, trees and several other data structures. One handy feature of tables is to use strings as keys—for example:
x = { ["hello world!"] = "ciao world!" }
print(x["hello world!"])
When running this example, Lua outputs “ciao world!” and not “hello world!” as it might appear.
For a more in-depth look at Lua's tables go to lua-users.org/wiki/TablesTutorial.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- Web & UI Developer (JavaScript & j Query)
- UX Designer
- Designing Electronics with Linux
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Nice article, thanks for the
1 hour 35 min ago - I once had a better way I
7 hours 21 min ago - Not only you I too assumed
7 hours 38 min ago - another very interesting
9 hours 31 min ago - Reply to comment | Linux Journal
11 hours 25 min ago - Reply to comment | Linux Journal
18 hours 19 min ago - Reply to comment | Linux Journal
18 hours 35 min ago - Favorite (and easily brute-forced) pw's
20 hours 26 min ago - Have you tried Boxen? It's a
1 day 2 hours ago - seo services in india
1 day 6 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Not really a fair treatment of Python though, is it?
def frac(n):
if n == 0: return 1
else: return n * frac(n - 1)
Evaluating
frac(10)gives the result 3628800 whilefrac(30)returns 265252859812191058636308480000000L.h = {1:'hello', 2:'world'}
for k, v in h.iteritems():
print k, v
In general it's a good article, it shows off some interesting points in Lua. In order to make a comparison between two languages it's necessary to have very good knowledge of both languages, otherwise there's a real risk that one language is the favourite simply because the author knows that one the best. This piece definitely suffers from that.
I also believe it would have been better without the author's personal opinions on aesthetics sprinkled across the piece.