Programming in Lua 2nd Edition
Andre Carregal writes "In the second edition of Programming in Lua Roberto Ierusalimschy presents the Lua programming Language in a simple yet precise format for both novice and advanced programmers." Read the rest of Andre's review.
Programming in Lua, 2nd Edition
author
Roberto Ierusalimschy
pages
328
publisher
Lua.Org; 2nd edition (March 5, 2006)
rating
10
reviewer
Andre Carregal
ISBN
8590379825
summary
Shows how Lua is the language of choice for anyone who needs a scripting language that is simple, efficient, extensible, portable, and free.
The Lua programming language has been around for more than 10 years, but only recently has it started to appear on the mainstream radar screens. It has evolved from a simple scripting language to a full-fledged solution for scripting and embedding. Lua is portable, fast and small, and the language of choice for applications as diverse as games, Web sites and robot controllers as the Lua Users Wiki and LuaForge will confirm.
Lua portability can be shown by the long list of operating systems it runs on, which includes not only Windows and Linux, but also small systems and mobile devices. The memory and CPU requirements for the runtime are really low, and Lua has been used in environments that most other scripting options would not dare go into.
One of the milestones of the history of Lua has been the release of the book Programming in Lua (a.k.a "PiL"), by Roberto Ierusalimschy, in 2003. This review is about the second edition of Programming in Lua, a.k.a. the "Blue PiL" due to the color of its cover.
Lua is free software and can be obtained from its site (www.lua.org). There you will also find the reference manual of the language and the full contents of the first edition of Programming in Lua.
As a disclaimer, let me say that I'm one of the technical reviewers of the book and I have been working with Lua since 1993, most of the time interacting with Roberto Ierusalimschy, even when not working in the same projects as him.
The second edition manages to surpass an already good book in various aspects. The "Blue PiL" presents not only the language itself, but also gives an excellent view of how one could see Lua as the foundation of solid scripting techniques. The original Programming in Lua was focused on Lua 5.0, while the second edition focuses on Lua 5.1. While the differences between Lua 5.0 and 5.1 are not radical, the newer version has a lot more to offer, both in terms of the modularity aspect and of language features. The second edition of Programming in Lua indicates clearly when some concept or detail relates only to a specific version of Lua, but most of the contents can be applied to both Lua versions.
Programming in Lua is oriented to both the novice programmer who wants to get a first feeling for Lua, and to the advanced Lua or C programmer who wants to use the full potential of the language. The book clearly separates the two aspects and indicates the sections that can be skipped for each reader profile. The author manages to keep a light and easily readable style during the whole book and the examples are simple and direct, making the flow of the reading quite pleasant. I can say that, even having some reasonable experience with Lua, I was surprised by a lot of details in the book. The "Blue PiL" is one of those books that you can read many times over, and each time you learn something new.
The "Blue PiL" starts with an overview of the Lua language and slowly evolves through the more advanced concepts and the features that make Lua such a unique language. Even though it's a relatively thin book, it goes from the starting concepts to the more sophisticated ones with a grace that is really rare to find. The one other book that comes to mind with an effect like this is the classical Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman, which says a lot.
The first part of the book presents the language and the basic features. In particular, concepts such as iterators, coroutines and closures are presented in a clear way, which is no small feat considering that many readers will be having contact with such concepts for the first time.
One of the strong points of Lua is its simplicity, but don't assume that this implies lack of power. An example of this balance is the table data structure, in fact the only data structure for Lua. Tables allow the construction of every other data structure (arrays, sets, bags etc) but also allows the use of sophisticated techniques such as metamethods, function environments, modules and object orientation.
In fact, instead of providing every feature one might want to use, Lua provides the meta mechanisms so you can create your own features, or use them as modules created by third parties. In order to explain the full power of these meta mechanisms the second part of the book takes the reader from the basic steps of creating a table and shows how each of the mechanisms can add features or help the usage of some advanced concepts.
As an example, the chapter on object-oriented programming not only shows how to use objects in Lua, but also how to think of objects as prototypes for other objects, and how to implement inheritance on such a model without using anything too fancy.
There are also chapters on the use of metatables (basically tables that define the behavior of other tables), the use of tables as function environments (a really powerful mechanism once understood), modules and finally weak tables. Weak tables allow the advanced use of memory resources in an automatic way, providing mechanisms for data structures that tend to be hard to implement in other languages, if even possible at all.
This slow but efficient presentation of concepts that, though complex, can be easily assimilated by the reader is a predominant aspect of Roberto's work. He is not only a skilled author but also knows how to present things in a way that a novice can grasp and an expert can master.
The third part of Programming in Lua covers all the language libraries (math, table, string, system, debug and I/O) in clear prose and shows that even with a small set of libraries Lua can pack a lot of power on a very small footprint.
Finally, the last part of the book is directed to programmers that want to use Lua to its full potential. Lua can be used as an extension language or as an embedded language, and knowing how to interact with the host language (C, C++, Java, Delphi etc.) is mandatory for that. The book presents the C API for Lua in the same progressive pace, but also manages to cover every ground needed so one can add Lua to a project without much pain, if any.
One important thing to note about the book is that it follows the same philosophy that guides the language, showing that simplicity and lightness has nothing to do with lack of power or coverage.
I really recommend this book to anyone interested in learning Lua, and also for those who already know how to use Lua but would like to fully master its way of thinking, the so called "Lua way" of doing things. The book has been considered by many as an excellent guide on programming, even if one is not interested in Lua in particular."
You can purchase Programming in Lua, 2nd Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
The Lua programming language has been around for more than 10 years, but only recently has it started to appear on the mainstream radar screens. It has evolved from a simple scripting language to a full-fledged solution for scripting and embedding. Lua is portable, fast and small, and the language of choice for applications as diverse as games, Web sites and robot controllers as the Lua Users Wiki and LuaForge will confirm.
Lua portability can be shown by the long list of operating systems it runs on, which includes not only Windows and Linux, but also small systems and mobile devices. The memory and CPU requirements for the runtime are really low, and Lua has been used in environments that most other scripting options would not dare go into.
One of the milestones of the history of Lua has been the release of the book Programming in Lua (a.k.a "PiL"), by Roberto Ierusalimschy, in 2003. This review is about the second edition of Programming in Lua, a.k.a. the "Blue PiL" due to the color of its cover.
Lua is free software and can be obtained from its site (www.lua.org). There you will also find the reference manual of the language and the full contents of the first edition of Programming in Lua.
As a disclaimer, let me say that I'm one of the technical reviewers of the book and I have been working with Lua since 1993, most of the time interacting with Roberto Ierusalimschy, even when not working in the same projects as him.
The second edition manages to surpass an already good book in various aspects. The "Blue PiL" presents not only the language itself, but also gives an excellent view of how one could see Lua as the foundation of solid scripting techniques. The original Programming in Lua was focused on Lua 5.0, while the second edition focuses on Lua 5.1. While the differences between Lua 5.0 and 5.1 are not radical, the newer version has a lot more to offer, both in terms of the modularity aspect and of language features. The second edition of Programming in Lua indicates clearly when some concept or detail relates only to a specific version of Lua, but most of the contents can be applied to both Lua versions.
Programming in Lua is oriented to both the novice programmer who wants to get a first feeling for Lua, and to the advanced Lua or C programmer who wants to use the full potential of the language. The book clearly separates the two aspects and indicates the sections that can be skipped for each reader profile. The author manages to keep a light and easily readable style during the whole book and the examples are simple and direct, making the flow of the reading quite pleasant. I can say that, even having some reasonable experience with Lua, I was surprised by a lot of details in the book. The "Blue PiL" is one of those books that you can read many times over, and each time you learn something new.
The "Blue PiL" starts with an overview of the Lua language and slowly evolves through the more advanced concepts and the features that make Lua such a unique language. Even though it's a relatively thin book, it goes from the starting concepts to the more sophisticated ones with a grace that is really rare to find. The one other book that comes to mind with an effect like this is the classical Structure and Interpretation of Computer Programs by Harold Abelson and Gerald Jay Sussman, which says a lot.
The first part of the book presents the language and the basic features. In particular, concepts such as iterators, coroutines and closures are presented in a clear way, which is no small feat considering that many readers will be having contact with such concepts for the first time.
One of the strong points of Lua is its simplicity, but don't assume that this implies lack of power. An example of this balance is the table data structure, in fact the only data structure for Lua. Tables allow the construction of every other data structure (arrays, sets, bags etc) but also allows the use of sophisticated techniques such as metamethods, function environments, modules and object orientation.
In fact, instead of providing every feature one might want to use, Lua provides the meta mechanisms so you can create your own features, or use them as modules created by third parties. In order to explain the full power of these meta mechanisms the second part of the book takes the reader from the basic steps of creating a table and shows how each of the mechanisms can add features or help the usage of some advanced concepts.
As an example, the chapter on object-oriented programming not only shows how to use objects in Lua, but also how to think of objects as prototypes for other objects, and how to implement inheritance on such a model without using anything too fancy.
There are also chapters on the use of metatables (basically tables that define the behavior of other tables), the use of tables as function environments (a really powerful mechanism once understood), modules and finally weak tables. Weak tables allow the advanced use of memory resources in an automatic way, providing mechanisms for data structures that tend to be hard to implement in other languages, if even possible at all.
This slow but efficient presentation of concepts that, though complex, can be easily assimilated by the reader is a predominant aspect of Roberto's work. He is not only a skilled author but also knows how to present things in a way that a novice can grasp and an expert can master.
The third part of Programming in Lua covers all the language libraries (math, table, string, system, debug and I/O) in clear prose and shows that even with a small set of libraries Lua can pack a lot of power on a very small footprint.
Finally, the last part of the book is directed to programmers that want to use Lua to its full potential. Lua can be used as an extension language or as an embedded language, and knowing how to interact with the host language (C, C++, Java, Delphi etc.) is mandatory for that. The book presents the C API for Lua in the same progressive pace, but also manages to cover every ground needed so one can add Lua to a project without much pain, if any.
One important thing to note about the book is that it follows the same philosophy that guides the language, showing that simplicity and lightness has nothing to do with lack of power or coverage.
I really recommend this book to anyone interested in learning Lua, and also for those who already know how to use Lua but would like to fully master its way of thinking, the so called "Lua way" of doing things. The book has been considered by many as an excellent guide on programming, even if one is not interested in Lua in particular."
You can purchase Programming in Lua, 2nd Edition from bn.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Of course, if you grew up with a last name like "Ierusalimschy", reading Perl aloud is probably pretty old hat for you. For that matter, so are APL and Brainf*ck.
... for the Burning Crusade expansion of World of Warcraft (Lua 5.1) and customized UIs!
Every page has a donation or Amazon link...
Anyways the ref book is online:
http://www.lua.org/manual/5.1/
Just what the world needs, another 'toy' programming language, a solution in search of a problem. Toss this aside next to the java books. A cute theoretical analysis, but more or less useless in the real world.
Disclaimer or not, should he be allowed as a reviewer?
Hmm, the Review Guidelines stateSo, it OK according to the guidelines. Though, i'd wonder if someone so involved is a good person to actually write such a review.
Have you read my journal today?
But, I want to see how deep the rabbit hole goes!
as a short introduction to the LUA language I present here the code for a hello world app:
print "Hello world"
hope that helps...
And considering that Amazon has the book for cheap, and the project favors it, it's ridiculous that Slashdot links to the always overpriced B & N.
Cracky-Chan Up, Mercatur Down!
If you want to geek out a bit and program Lua on your Palm, you may do so: http://netpage.em.com.br/mmand/plua.htm
Space and Computers.
How so? Last I checked, anyone is free to modify Lua to their heart's content and include the modified Lua VM in their program, and they can choose whether or not to release the source. That's even more free than what the GPL states, if you consider Lua's domain. Remember, Lua has been and is still used by many game developers who don't necessarily want modifications done to their games (or at least to their games' code, if not the data), and Lua would probably have failed in that market if it had a restrictive, bossy license like the GPL behind it. Lua is anything but DOA.
Slashdot requires you to wait longer between hitting 'reply' and submitting a comment.
Read the article again, and this time remember that "lua" is a word the Hawaiians use for the bathroom.
Who cares.. we need more submissions about blatantly homosexual WoW characters.
If you need a reason to learn Lua, look no farther than Celestia.
Lua is the more powerful of the two scripting languages that can be used with Celestia. You can do some awesome stuff with it, and there are lots of examples on various forums (fora?) devoted to Celestia scripting. Good times.
http://www.lua.org/uses.html list an impressive amount of project (many of them games) using lua.
More to the point, given that Lua is widely used, only an idiot would try to claim that Lua is "DOA" because of its license.
How can we continue to believe in a just universe and freedom to eat crackers if we have no ale?
Although Lua's killer app seems to be as a scripting engine for games, it's also a good general-purpose data description language. I used it for that purpose, for a little database where the alternative would have been a csv file, and it worked out well. I would also be interested in people's thoughts about Lua vs Guile. They're both used as scripting engines for a lot of open-source apps, and they're also both good data description languages. Would the main difference be speed? Performance? Licensing? Portability? Personal taste in syntax?
Find free books.
I've read about 3/4 of the book so far and I completely agree with the reviewer's assessment. It's very cleanly and clearly written, with many things explained in a concise and elegant style. For example, Ierusalimschy's explanation of closures allowed me to immediately grasp them and appreciate why they are useful. I remember reading about them way back years ago in Larry Wall's book 'Programming Perl', and was remained rather confused about the concept. I don't know if the additional years of experience helped, but the clear style of the Lua book certainly did.
Using a scripting language for enhancing and extending a complex project just seems to be a given for most serious projects these days, and after surveying the field, I considered only two main choices: Python and Lua. Python is also really well designed and powerful, but I decided to go with Lua because it does pretty much everything I need it to do, does it very well, but best of all, it is so very small. These days when even the most basic projects can quickly grow into complex, interconnected monstrosities with a zillion dependencies, I believe that the values of small and simple are more important than ever. So for that reason especially, I'm really excited about Lua and the prospect for using it more effectively after I finish swallowing this Blue PIL.
mhack
Building a better ribosome since 1997
Programming in Lua is simply one of the best books on programming I have ever read. It's "The C Programming Language" of Lua.
That would be "lua lua".
Wow, that's the most brain-washed open-source zealot response I've seen in a while. Do you even understand the "free as in beer" line at all? Apparently not.
If it really, really, really bothers you that Lua doesn't have enough restrictions on distribution, you are quite free to download a copy, stick a GPL license on it, and use that. How about that?
Caveat Utilitor
Chacham Cow ...and most of the adults ...without the horns ...and a few more clicks
It was a morning just like any other morning
In the Sinai desert, 1200 B.S. (Before Slashdot)
It glistened, it glowed, it rose from the gold of the children of Israel
The chacham cow!
The golden chacham cow had a body like the great cows of ancient Egypt
And a face like the face of Cowboy Neal
And through the centuries it has roamed the earth
Like a ravenous bovine
Seeking whom it may lick
chacham cow!
From the valley of the shadow of fark
To the on-line gambling boutique
From the depths of youtube
To the custom style sheet
The chacham cow lurks
The chacham cow lurks
Who loves you, baby?
Who'll give you good karma?
Who says you'll regret it?
Aaa-ooooooo
Who loves you, baby?
Who'll give you mod points?
Who says you'll regret it?
Aaa-aaa-aaa-ooooooo
I was in love and I needed the clicks
And then I needed more clicks
I was filthy rich and all I wanted were more page views
Woe to you, proud mortal
Secure in your modest digs
You think you're immune?
You, who couldn't finger said cow in a police line-up with the three little pigs!
chacham cow!
Master of disguises!
Who's gonna change shape at will?
Who's the eye on the pyramid on the back of the dollar bill?
Who loves power lunchin' from boing-boing to digg?
Who loves you, baby?
chacham cow comin' to get ya
Why?
Cuz you think this is stupid, don't you?
The chacham cow will not be mocked!
The chacham cow's planning a coup!
The chacham cow chews cud bigger than you!
Woe, woe, woe to you
Who blow off this warning
Perhaps you've already been licked
I, too, was hypnotized
By those big cow eyes
The last time I uttered those four little words
"I deserve better editors!"
It's hard to believe that's how Micronians are made. Why don't we see it right now by having you both kiss one another?
> Wow, that's the most brain-washed open-source zealot response I've seen in a while.
No zealot of the GP's stripe would ever consider using the term "open-source", which Lua most certainly is.
Sometimes even RMS is pragmatic -- I recall when he was advocating that Ogg Vorbis use the BSD license. I really don't know what prompted that change in tune for just that one instance, since as far as I can see, it's yet to be repeated.
Done with slashdot, done with nerds, getting a life.
The 'neat' thing about this language seems to be its easy memoization of functions. That would make it a good choice for programs that do certain kinds of calculations (and by the look of it, calculations that tend to be used in games).
Any of these 'new language X' are written to tackle a particular problem set. Would you use perl or C do to string munging? Would you use perl or Fortran to do fast and heavy number crunching? Being aware of what languages are out there may save you time when you encounter a particular problem.
I saw bring the new languages on. At the very least, their useful bits will be incorporated into a future perl release.
I just discovered Lua and I got my PiL today. Its an fantastic language! It executes faster than perl, php, python and ruby. It is alot smaller, round 200kb, which is less than 1/10 of a minimal php installation and it has a reasonable Licence (MIT).
The main drawback is the lack of good standard libraries and the build system (for lua 5.1) don't support DSO's on linux. Debian has some patches that uses libtool to build it.
There is an interesting projocet named haserl that will allow you to embed lua in html pages.
First Edition of the book is available online
You say LUA Guru.
Then when they question you, look at them as if they are below you in all ways, then write on the board print "Hello world"
then say "Is testing my knowledge really an indicator? during an interview? I think not."
The go on as if you got the job and the interview is just a minor inconvience.
The Kruger Dunning explains most post on
You apparently wouldn't know "libre" if it bit you in the ass.
It's always a long day... 86400 doesn't fit into a short.
The syntax is similar to Pascal. No thanks. Out of all the languages I would be least likely to model a new langauge syntax after, Pascal and Lisp would be near the top.
The freeware windows shell, Litestep, now has a lua scripting module to do those tasks that you could probably have done before, but way faster.
http://www.shellfront.org/modules-list.php can provide you with the module, for those that are interested.
in brazil,from where this script language come from,lua = moon
World of Warcraft's UI system is programmed in LUA & something else, can't remember gotta go raid, kthxbye
How much is your data worth? Back it up now.
Even if you have no plans to actually program in Lua, you should get this book as an example of how a technical book can and should be written!
While the novice programmer can certainly pick this book up and learn to program (and it is perfectly suited to that), the examples, asides, and discussion in each chapter contain gems for the intermediate to advanced programmer. Everytime I look something up I see a new depth to some language feature or example I didn't see the first time around.
I use Lua because it is incredibly easy to both extend lua with either C or C++ libraries as well as embed lua in my C/C++/ObjC/whatever programs
Try Squirrel
Free Software: the software by the people, of the people and for the people. Develop! Share! Enhance! Enjoy!
Who the fuck cares, you are obviously a communist bastard. Fuck GPL.
Well, the first reaction of many people might be
"O no, yet another scripting language finds it way from the obscurity into the lame light". Do we need an extra one if we already have Ruby, Python, Perl, Tcl, Scheme. And I say -- YES, Lua has its place, it is not redundant, it is not "me too" language. And here is why.
I have been expert Ruby coder for the last 5 years using Ruby for data modelling, extensive scripting, wrote load-balancing scripts, Rails Web development, binding C++ libraries to Ruby using SWIG, you name it.
Six month ago I got involved in LUA and I totally fell in love with it.
What does make a beautiful programming language? Lots of features? wealth of libraries? simplicity of it? I think that language design is more art than science and the language beauty is the careful balance of features, simplicity, semantics, uniformity, etc. Like in a masterpiece painting it is the balance of color, shapes, motives and composition.
C, for example, ia a beautiful language in the category of "portable assemblers". In that category C is powerful thanks to its libraries, simple and easily implementable thanks to its syntax and semantics, portable due to very clever and clean hardware abstraction.
I think that Lua is to "high level scripting languages" is what C is to "portable assemblers". Lua has both OO and functional programming very naturally represented in its semantics. All objects are first class (including functions). Lua is small, very fast (in fact fastest scripting language according to http://shootout.alioth.debian.org/), has very good Virtual Machine, incremental Garbage Collector. As far as fundamantals are concerned, Lua is light-years ahead of Ruby. It still lags behind in library support, but the recent progress is very encouraging.
Anyway, give Lua a try. You will love it. Lua is nice, its codebase is tiny (about 10K lines). It runs on anything that support ANSI C compiler including embedded stuff (ARM, Palm, Cell phones, MIPS, x86, etc).
The best part about this book is how applicable it is to other languages: Even though it doesn't directly touch any others, of course, it introduces things like closures and tail recursion in a very good way for both intermediate programmers and newbs to understand and apply to, say, Perl.
So in other words, he recommends the book to:
1 - People who want to learn LUA;
2 - People who already know LUA but may want to know more about it;
3 - People who don't want to learn LUA (or simply the rest of the human race).
After telling us how close to the project he is, the third reason sounds to me like: "Oh and by the way in, case you don't need the book at all here some random reason to try to convince you to buy it anyway." In the same vain he could have said:
The book has been considered by many as an excellent base ingredient to make"papier-maché" scultures , even if one is not interested in Lua in particular."
The book has been considered by many as an excellent cockroach crusher, even if one is not interested in Lua in particular."
The book has been considered by many as an excellent way to make a fire in case you are stranded on a tropical island after a plane crash, even if one is not interested in Lua in particular."
Yahh, hiii haaaaa! -Major Kong, from Dr. Strangelove
Brazil? Doesn't everyone know that programming languages come from Denmark?
Lua means "moon". No closer to moron than "lunacy" is to "moon".
I think Lua's main selling point is ease of embedding. When you write a large C++ application, you frequently end up wanting some embedded scripting language.
Some interpreters, like Perl, are tricky to embed. Lua is very friendly to embedding. You can call user-defined Lua functions from C and call C functions from Lua.
The interpreter is small, and the language is sandboxable - for instance, you could have untrusted Lua running in your webserver and it would have no access to I/O or filesystem.
I do not believe in karma. "Funny"=-6. Do good and forbid evil. Yours, Oft-Offtopic Flamebaiting Troll.
I just cringed when you were grouping Perl with Java there... For that matter, I'd cringe if anyone would group any language with Java. It's really hard to make comparisons when you know that Java is pretty much always the worst choice in efficiency, speed and transparacy.
:(
But oh well
Splut.
Coz eternity my friend, is a long *ing time.
No need for Libre, I'll just go with a Cuba plain, please, possibly over some ice.
But to get back to licensing, LUA probably has the best licensing for a scripting language of its ilk, considering the fact it's an ideal candidate for full embedding in anything that needs object oriented smart scripting (which applies to pretty much all games with 'mobiles' or XML based UI's), so actually giving it the licensing it has was a brilliant move to get it spread.
Splut.
Coz eternity my friend, is a long *ing time.