
xv
tend to think of Lua as a language specifically designed for the Web; players of
a specific game may regard Lua as a language exclusive to that game.
Lua is useful also as a stand-alone language, not only for text-processing
and one-shot little programs, but increasingly for medium-to-large projects, too.
For such uses, the main functionality of Lua comes from libraries. The stan-
dard libraries offer pattern matching and other functions for string handling.
(We may regard the stand-alone language as the embedding of Lua into the
domain of string and text-file manipulation.) As Lua improves its support for li-
braries, there has been a proliferation of external packages. The Kepler project
(http://www.keplerproject.org), for instance, is a Web development platform
for Lua that offers packages for page generation, database access, LDAP, XML,
and SOAP. The LuaForge site (http://www.luaforge.net) offers a focal point
for many Lua packages.
Finally, there are those programmers that work on the other side of the
bench, writing applications that use Lua as a C library. Those people will
program more in C than in Lua, although they need a good understanding of
Lua to create interfaces that are simple, easy to use, and well integrated with
the language.
This book has much to offer to all these people. The first part covers the
language itself, showing how we can explore all its potential. We focus on
different language constructs and use numerous examples to show how to use
them for practical tasks. Some chapters in this part cover basic concepts, such
as control structures, but there are also advanced topics, such as iterators and
coroutines.
The second part is entirely devoted to tables, the sole data structure in Lua.
Its chapters discuss data structures, persistence, packages, and object-oriented
programming. There we will unveil the real power of the language.
The third part presents the standard libraries. This part is particularly
useful for those that use Lua as a stand-alone language, although many other
applications also incorporate all or part of the standard libraries. This part
devotes one chapter to each standard library: the mathematical library, the table
library, the string library, the I/O library, the operating system library, and the
debug library.
Finally, the last part of the book covers the API between Lua and C, for those
that use C to get the full power of Lua. This part necessarily has a flavor quite
different from the rest of the book. There we will be programming in C, not
in Lua; therefore, we will be wearing a different hat. For some readers, the
discussion of the C API may be of marginal interest; for others, it may be the
most relevant part of this book.
About the Second Edition
This book is an updated and expanded version of the first edition of Program-
ming in Lua (also known as the PiL book). Although the book structure is virtu-
ally the same, this new edition has substantial new material.
Property of Samuel El-Borai <georgesleyetidoux@gmail.com>