Beginning Lua Programming 173
Simon P. Chappell writes "These days, Brazil is no longer just on the map for its fine coffee and martial arts. They have a few other reasons and one of them is called Lua. Lua is an open-source scripting language that was originally designed for small size and excellent portability to support its use in embedded systems. Like anything good, it didn't take long for it to be discovered by others looking for a small and efficient scripting language."
Beginning Lua Programming | |
author | Kurt Jung, Aaron Brown |
pages | 400 |
publisher | Wiley |
rating | 9 |
reviewer | Simon P. Chappell |
ISBN | 0470069171 |
summary | A great introduction to Lua with solid writing and explanations of the concepts |
This is definitely a book targeted at those new to Lua. While it begins gently, it picks up speed quite quickly and takes its reader through a full range of Lua usage. This book is unusual, for the more mass-market beginner books, in that it does not treat the reader like an idiot. I found the tone to be very respectful of the reader's intelligence. This aspect alone, makes the book stand out in a crowded beginners market.
This book is also a very good introduction to Lua for programmers experienced with one or more other programming languages. I found it very easy to pick up the concepts with my previous programming experience.
The first chapter of most books like this, will typically cover getting setup with the language. This book delivers well, with not only explaining how to install the binary version, but also covers compilation under Unix-styled operating systems and a number of development environments for Microsoft Windows. Guidelines are given for building Lua on Windows using Visual C++, Tiny C and MinGW.
Chapter two is called "First Steps" and is a walkthrough of all of the core language. This is well done and there are plenty of examples where a Lua command is typed and the resulting display from the Lua environment is shown. Chapter three is dedicated to the art of the Lua function. Functions are first class values and have enough power and complexity that they deserve their own chapter. Did you know that Lua automatically recognises tail recursion and handles it appropriately? It does. So if your looking to experiment with some of the trendy functional techniques that tend to swamp Reddit these days, Lua would be a good place to try it.
Chapter four explores Lua's only data structure, the table. What's a table, you ask? My best description, as far as I've managed to get my head around it, would be that it's a Swiss-Army Knife style Hash Table with multiple personalities, alternatively thinking that it's an array, a list, an Erlang-style tuple or a tree structure. However you decide to use it, this chapter explains it and provides lots of examples. Chapter five brings us that ultimate datatype, the string. As with tables, Lua can do many things with the humble string and this chapter will make sure that you can work with substrings, handle user input, read and write files and use the built-in pattern matching available in the language.
Chapter six covers "Handling and Avoiding Errors". I know, I know, we don't have errors anymore, now that we've all discovered the benefits of agile development using scripting languages. Except that we do and circumstances external to our programs can still bring pain to our code. Users type the wrong things, network connections die, power can go out suddenly and, of course, sometimes there are parts of our programs that aren't as imperfect as we'd like to think they are. Chapter seven is about "Using Modules" and explains Lua's interfaces and implementations together with guidelines on modularising scripts and calling those modules.
Any agile language worth its electrons is going to have meta-programming facilities within it. Lua has them and chapter eight is where we learn about "Extending Lua's Behaviour with Metamethods". Chapter nine examines Lua's ability to handle events using coroutines. This is a powerful feature and enables Lua applications to manage concurrent tasks with ease.
Chapter ten explores the fascinating world of Lua internals. While Lua is a scripting language, it does use a virtual machine, this chapter shows how scripts can be pre-compiled to the appropriate bytecode. It also covers memory management and implementation details for tables and strings. Chapter eleven is somewhat reference-like, covering the standard libraries supplied with Lua. Chapter twelve is a good compliment, describing some of the available libraries from the Lua community.
Chapter thirteen addresses the matter of interfacing Lua with other languages. If your language can handle C-style calling conventions, then it can be used by your Lua programs. Chapter fourteen is for everyone that wishes to store information in a database now and then. Lua has bindings for connecting to a number of popular database systems and this chapter will help you use them.
My favourite chapter is number fifteen, where using Lua for web applications is explained. There are several alternatives for the budding Lua web application programmer, ranging from that humble and faithful technique, the CGI script, to the Kepler web server environment with the convenience of LuaPages. In this highly-connected world, it is important to be able to communicate over a network and if chapter fifteen didn't tip you off, then chapter sixteen will make you absolutely certain that Lua is ready for networks. Chapter sixteen explores networking from LuaSockets to email and webpages.
Lua is very popular among video games designers. While not generally used to write the frameworks, it is often used for in-game scripting. Chapter seventeen recounts many of the ways that Lua can be used within video games. Chapter eighteen will appeal to the Palm carrying geeks in the house. If you've been looking for a programming language for your Palm PDA, then Plua may be just what you were looking for. Plua (actually Plua2, but they call it Plua) is an implementation of Lua 5.0 for the Palm OS. It gives full access to both data and graphics and is programmable on the Palm; no need to be tethered. Finally, chapter nineteen addresses the subject of "Fitting into the Lua Community".
That's a long list of chapters. Phew! After all of that, let's see what was worth noting along the way.
The writing style is good. Light without being flippant and respectful of the readers intelligence. I like that. I liked the fact that the topics were broken down into appropriately sized chapters. It meant that this book has more chapters than usual, but each one is nicely partitioned, so it doesn't feel over-whelming. I also like the fact that this book seems like it will continue to be useful in the medium term as well. Some beginners books stop being useful quite quickly after you've learned the basics from them, but this one covers quite a number of topics that will useful at the mid-level of Lua skills.
I have very little negative to say about the book. While I normally don't care for books much larger than 300 pages, this one doesn't feel like it has any gratuitous stuffing in it. There is an appendix with answers to the programming questions asked here and there in the chapters, but other than that, everything feels like it should be there.
As a typography and layout nut, I did feel that the layout was a little cramped and the primary type size was a little small. The program listings were generally well done, although I'm not sure that every single one needed a gray background to help separate it from the body text.
The title of chapter nineteen, "Fitting into the Lua Community" seemed a little patronizing to me. I understand the need for maintaining community values, but most communities do that fairly well without the aid of authors playing the heavy. Apparently the community lasted this long without the book. Let's hope they make it a little longer, now that the masses know about it.
All in all, this is a great introduction to Lua. It has solid writing and explanations of the concepts, with plenty of examples. Recommended.
You can purchase Beginning Lua Programming from amazon.com. Slashdot welcomes readers' book reviews -- to see your own review here, read the book review guidelines, then visit the submission page.
Small? (Score:3, Insightful)
Small and efficient? Sure, for now. But wait until the rest of the OSS community gets done with it. I give it two years tops before, like PHP, it's been "extended" with 1.67 million indecipherable functions.
Re:Another scripting language? (Score:5, Insightful)
Lua is useful because it's easy to fold into other programs. Lua is what you pull out when you're writing an application in a non-scripting language but you decide to make part of it user-scriptable. Conversely, you may be using one of those applications, in which case there are Lua scripts around for you to play with.
Insane gang and prision violence?? (Score:1, Insightful)
Re:The ignorant and SlashDot authorship... (Score:5, Insightful)
Mardi Gras?
There is no such thing in Brasil. I guess you mean carnival [wikipedia.org], it differs from mardi-gras in the ammount of naked people (and crossdressers).
Nazi hideout?
I think you confused Brazil with Argentina [wikipedia.org]. A lot of criminals flees to Brasil, a lot are born there, but Nazi is not really our specialty, as our ethnic diversity would easily get them mad and bust their covers.
Soccer?
We don't know this sport there. But we are five times champions of Football (Association), if that is what you mean. (Tongue in cheek)
Regardless of that, I agree with your take, Brasil is not known only by its fine coffee and Martial Arts. It is not even known by it's Martial Arts, for god sake, except for people that follows MMA and know that Brazilian Jiu Jitsu exists (we in Brazil don't call it that, we call it only Jiu Jitsu).
The general sensation in Brazil is that we are known by our futebol, our samba and carnival, our giant man-eater screaming snake overlords (anacondas), our monkeys and our natural beauties (landscapes and women).
It is extremely easy to embed. (Score:5, Insightful)
I don't know that I would go out of my way to learning it just to learn it, but I would love to see it become the defacto scripting language for linux desktop apps.
Cue the toilet humor (Score:3, Insightful)
I guess all the Americans here didn't get it.
Re:when they say "lightweight"... they mean it (Score:3, Insightful)
Re:The ignorant and SlashDot authorship... (Score:2, Insightful)
Step up to Lua (Score:1, Insightful)
Although there is good progress with the Kepler project, there is not yet a sparkly project like 'Rails' that actively promotes the language.
Explanation of "Fitting into the Lua Community" (Score:2, Insightful)
No, that won't happen. To understand why, you first have to understand what the reviewer meant by "Fitting into the Lua Community". This was a mighty unusual chapter to find in a book, and many will have wondered what was behind it. Well, there is no substitute for experiencing it yourself directly, but here's a small explanation by way of preview.
The Lua community is odd, very odd. It contains many extremely bright people, totally immersed in the language and able to make it do the most incredible things. And these very bright people naturally make many very insightful and valuable suggestions about what should be added to the language to make it ever better and more consistent and flexible.
And they are *ALL* ignored by the author, Roberto. And they don't care.
And that is what is odd about the Lua community. It is utterly static, stagnant and neutered, because the language's author might as well be carved out of stone, petrified, entombed in carbonite and held in a stasis field, for all the suggestions he accepts. Which is none, zero, the empty set. Ever.
(I'm excluding bug fixes; he does react to bug reports, but takes nothing else on board, regardless of source, merit, the number of people asking for it, nor the number of years over which they have been asking. It matters nothing to him, because ideas are only allowed to come from his own brain, full stop. He happily discusses everything, but adds absolutely nothing to *HIS* language as a result of those high-volume disussions. It's been so for many, many years, and it's now engrained in that community.)
So there you have it. Lua is an open-source language, but it does not have an open design. The design is utterly closed, and its author is immoveable. And the fanboys, like all fanboys everywhere, don't care, even when they themselves have been making the insightful suggestions which are always ignored.
So you see, there is no danger of Lua becoming bloated with open-community improvements. Because the openness stops dead at the foot of the author. There is not the slightest chance of any community-led improvements, at all.
Re:I'm sure I'm not the only one to point it out, (Score:3, Insightful)
If your natural numbers start with 0, then the Ordinality of n (the position number in the sequence of natural numbers) is equal to the Cardinality of n (the amount of numbers, that are smaller than n).
So whenever you have to talk about both position in (ordered) sets and size of sets, starting to count with 0 has its advantages.