| Related sites for http://www.unixreview.com/documents/s=8989/ur0405k/ |
| ABC-View_Manager Image managing and cataloguing tool that allows very fast thumbnail viewing, sorting, filtering, slideshow, randomisation, checking for duplicates and cataloguing into groups and series. | | Data_Science_Journal Peer-reviewed e-journal covering the management of data and databases in Science and Technology, data systems, applications and methods of data compilation or analysis. | | Taylor_Business_Software Offers modifications for the Open Systems Accounting Software line, and its own TBS package. Includes bug reporting, application registration and contact details. | | RFC_1444 Conformance Statements for Version 2 of the Simple Network Management Protocol (SNMPv2). J. Case, K. McCloghrie, M. Rose, S. Waldbusser. April 1993. | | RFC_1167 Thoughts on the National Research and Education Network. V.G. Cerf. July 1990. | | Radan_Computational_Ltd_ Produces a program for sheet metal manufacturing, including punching, nibbling, plasma/laser cutting, and nesting. | | FileGuru Categoriezed Windows listings form shareware, freeware and commercial programs. | | PerlWiz A Perl project-based editor and IDE for Windows with code templates, FTP, version control, web tools and tutorials. [Shareware] | | Tucson_Computer_Society_-_Access_SIG Tucson, Arizona, USA. | | ReportLab Authors of PDFgen, for generating professionally formatted printable documents on the fly. | | The_UCSF_Computer_Graphics_Laboratory The home to the Resource for Biocomputing, Visualization, and Informatics (RBVI), a NIH National Center for Research Resources Biomedical Technology Resource Center for the integrated analysis of biol | | Gnutella_com Gnutella information portal with community, development information and downloads. | | Silicon_Valley_Sleuth Technology news and analysis, focused on computers. | | ID_MOS Offers design services and IP for ASICs and FPGAs. | | Mercury_on_Microsoft\'s__NET_framework Describes the porting of the Mercury programming language to the .NET platform. | | Newave_WinMaster Tools collection for Windows with file management, screen capture, advanced system configuration, and system information. | | StarFire_Creations_Unlimited Provides web site content development, creation, and implementation. Located in Littleton, Colorado, United States. | | IBM_Smalltalk__The_Language By David N. Smith; Addison-Wesley, 1995, ISBN 080530908X. Written with IBM, encyclopedic coverage of the language, many examples to guide readers through concepts and methods of IBM dialect. [Addison- | | DeBolt,_Virginia Web design services including education, Austin, Texas. Has articles on various parts of web design. | | Photoshop_Tips_By_Hou_Seng Tutorials ranging from basic to advanced; text effects, menu and button creation, fun and games. |
|
Unix Review > Regular Expressions: Lua Shines

Unix Review > Archives > 2003 > December 2003
Print-Friendly Version
May 2004
Regular Expressions: Lua Shines
by Cameron Laird and Kathryn Soraiz
Take a look a Lua.
We write that every few years (most recently in May of 2002) because the Lua programming language is underappreciated, and because it continues to advance despite the comparatively small number of people working on and with it.
This spring, though, is a particularly good time to jump to Lua (the Portuguese word for "moon"), because Version 5.0 and The Lua Book are both better than we expected them to be.
Simple and extensible
Let's begin with a bit of background. Lua is a high-level or "scripting" procedural language, roughly comparable to Tcl, Python, Ruby, and similar languages. Lua source code has a familiar appearance; the canonical factorial definition with which the book begins looks almost like:
-- This is a comment.
function factorial(n)
if n == 0 then
return 1
else
return n * fact(n - 1)
end
end
Lua is around a decade old; Version 1.1 was the first public release in July of 1994. It's used mostly outside the United
States, with the core implementation team based in Brazil. Although Lua is far down the list of computing languages in wide use in the United States, at least a couple of development communities strong in the United States have recognized the language's virtues; a poll at GameDev.net, for example, yielded Lua as the most popular language for game scripting.
Game authors and other fans prize Lua over similar languages for its efficiency, simplicity, extensibility, and portability. While its syntax and semantics are much like those of other languages, with a few exceptions we'll mention below, its architecture and implementation are quite distinct. Lua is designed to be small and simple, and to "play well" with other technologies, values "Regular Expressions" touts monthly. Although Lua supports object-orientation quite satisfyingly, for example, the Lua approach to a big project is not, "How can the language support this 100,000-line task?", nearly as much as it is, "How can the language meet all the project goals in 2,000 lines?" Lua has a relatively weak presence as a standalone process; it appears to be used most in embedded contexts. Game developers, for instance, might build C-coded libraries of specialized display and algorithmic functions, then embed the Lua library as a convenient way to configure and manage the application end users see.
All this has been true since the mid-90s. During most of that time, too, a frequent topic of Lua-oriented conversation was, "where is the Lua book?" There's now a good answer to that question.
The book
The hazard we feel in writing about Programming in Lua (PIL) is that we'll sound condescending or biased or both. We looked forward to its publication in December 2003 because we've crossed paths with its author, Roberto Ierusalimschy, often enough to expect good things. The surprise was in just how good the book is.
Ierusalimschy, who heads the Lua development team and is a full-time professor at the Pontifical Catholic University of Rio de Janeiro, tried to work with major computing industry publishers. They were unencouraging. He finally decided to publish the book himself. The result is remarkable.
If PIL had just collected online references in a definitive, accurately indexed dead-trees version, it would have been a welcome volume. In fact, the prose is of high quality, far better than a reworked "man page" or help file, and its 288 pages include valuable discussions of topics covered almost nowhere else: industrial-strength metaprogramming and the architectures of extension and embedding. These, and its grown-up presentations of object orientation, concurrency models, and introspection, are so meaty that we recommend PIL to any intermediate or advanced developer. Even those indifferent to Lua as a development language will find the book presents so many good ideas, and presents them so artfully, that it's worth reading if only with the attitude that Lua is an idiosyncratic pseudocode.
PIL reads so unusually smoothly as to make one wonder whether being a native speaker of English and editorial support from a major publisher are somehow disqualifications for clear writing. The explanations are consistently graceful and concise, with the word order of "... it means probably something wrong in our program", on page 63, the only noticeable lapse from a fully idiomatic rendering.
Complementing the delights of PIL are the progress of version 5.0, which it documents. 5.0 includes co-routines, tail calls, booleans, "weak tables", improvements in exception handling, lexical scoping, and metatables. A quick example should give a bit of insight into Lua style, and how the book and the latest release support it.
Programming with metatables
Tables are important to Lua. Tables dictionaries or associative arrays, mostly are the language's central data structure. Part of the language's simplicity is that tables support only a few operations, including iteration through a table's contents, adding or removing key-value pairs, and so on.
One of the reasons Lua can be simple, yet still effective, is the way it leverages metaprogramming to achieve more subtle effects. Chapter 13 is on "Metatables and Metamethods". The first extended example there shows not only how to define a Set from mathematical set theory, supported by such operations as Set.union and Set.intersection, but also how to "overload" the addition symbol so that Set1 + Set2 is properly calculated as the union of these two sets. This requires only a couple of incremental lines of implementation:
function Set.new (t)
local set = {}
-- The next one is new.
setmetatable(set, Set.mt)
for _, 1 in $ipars(t) do set[l] = true end
return set
end
and
Set.mt.__add = Set.union
This is typical of good Lua coding in a couple of ways: not only does it achieve a powerful effect with small means, but it does so thriftily, in that Lua is still the fastest, or at least one of the fastest, "scripting languages", and Lua also retains its portability. All the new 5.0 features haven't impaired Lua's capacity to port easily to essentially any platform which supports ANSI C.
Our conclusion: you should get a copy of PIL. Read it; you're likely to understand quite a bit more about mixed-language programming, concurrency, and embedding, whatever your chosen languages. If you also happen to need a particularly lightweight extension language, and especially if you need one which performs well, the answer is likely to be at hand.
Administrative matters
Thanks for your patience. "Regular Expressions" has been on vacation much of the last six months. We have a mountainous backlog of good computing ideas that deserve coverage, and we're looking forward to a return to our usual monthly schedule for bringing them to you. Next month brings an experiment which dramatically illustrates how good scripting can get in scientific programming.
Kathryn and Cameron run their own consultancy, Phaseit, Inc., specializing in high-reliability and high-performance applications managed by high-level languages. Join them each month as their "Regular Expressions" column explores issues and opportunities that arise in practical application development with scripting languages.

Sys Admin Spotlight
CMP DevNet Spotlight
Christmas ChaosJerry shares his gift recommendations for tech-savvy friends and family.
In the News

CD-ROM
Sys Admin and The Perl Journal CD-ROM version 11.0
Version 11.0 delivers every issue of Sys Admin from 1992 through 2005 and every issue of The Perl Journal from 1996-2002 in one convenient CD-ROM!
Order now!


MarketPlaceBuild IT Knowledge with Current & Trusted ContentHelps Employees Develop & Hone New Technical Programming Skills. Sign Up & Get Full Access.Six Sigma Certification100% Online-Six Sigma Certificate from Villanova - Find Out More Now.Workflow Enabled Help Desk & IT Service ManagementAutomate service desk activities and integrate processes across IT. Learn more here.WinDev 11 - Powerful IDEDevelop 10 times faster ! ALM, IDE, .Net, RAD, 5GL, Database, 5GL, 64-bit, etc. Free Express versionWanna see your ad here?
© 2008 Think Services,
Privacy Policy,
Terms of Service
United Business Media Limited
Comments about the Web site:
webmaster@unixreview.com
Affiliated Sites:
BYTE.com,
dotnetjunkies.com,
Dr. Dobb's Journal,
SD Expo,
Sys Admin,
sqljunkies.com,
Unixreview
web2
|
|