Slashdot Mirror


Beginning Lua Programming

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.

173 comments

  1. LUA in WoW by Anonymous Coward · · Score: 5, Informative

    Blizzard uses LUA as the scripting language for macros and UI controls in the World of Warcraft MMORPG.

    1. Re:LUA in WoW by moochfish · · Score: 1

      Not trying to troll, but in all honesty with tons of other proven languages out there, why did blizzard bank on this one? what makes this language so great? i read the wiki article, but it seems like this is a relative new comer with very limited documented use in the production world (no pun intended), let alone a scaling application like WoW. Does anybody know?

    2. Re:LUA in WoW by XO · · Score: 2, Interesting

      The Far Cry and Crysis engines also use it. It's pretty popular, from what I've heard.

      I've looked at it and it looks like it'd be something really nice to incorporate into projects where you'd like to give people scripting abilities, but it's got some really really annoying things:

      It looks like a cross between Pascal and BASIC

      OK, well, that's all I could think of.
      It almost makes my head hurt.

      I suppose if I had been doing VB over the past decade instead of using all C-like languages, I could wrap my head around it .. but, I've been using C, C++, PHP, LPC, UnrealScript, and just about any other C-syntax language. Everyone else in the world has been using C-syntax languages too. Why did they come out with a bastardization of Pascal / BASIC together?

      I'd seriously want to use it if it were C-like.

      --
      "Champagne for my real friends - and real pain for my sham friends!" http://ericblade.postalboard.com/
    3. Re:LUA in WoW by aevan · · Score: 1

      Ragnarok Online also uses it for letting players customise/control their homunculi and hired mercenaries.

    4. Re:LUA in WoW by ceswiedler · · Score: 1

      It's popular because it's designed to be embedded. Other scripting languages are designed around being run as the top-most context of executiong, e.g. being run from the command line or when a user requests a web page. Lua is very easy to embed in your own app, so that for example you can write a script which can access the variables and functions of your running application. This is extremely useful for games in particular.

      You can easily hook up a Lua method to access a variable in your containing application. More importantly, any C function that you bind to a Lua method can return a special code which indicates that the function is "yielding". When that happens, the Lua interpreter pauses the script and returns to your application (the point at which you invoked the interpreter). Then later, you can "resume" the Lua script by providing the actual return value to the Lua method, which then picks up as if nothing had happened.

      Python can do something similar with coroutines, but again, it's not designed (as much) around being embedded so they're not as easy to use in that way.

    5. Re:LUA in WoW by cookd · · Score: 1

      Facts: Lua looks kinda like Pascal. The source is compiled to bytecode (at runtime or ahead of time) for efficiency. The license is not at all restrictive. The engine is about 90k compiled, 112k if you add all standard libraries. It runs very quickly for an interpreted language. The language is very simple (grammar fits on a page). The engine handles huge programs with no trouble. Lua implements closures (lexical scoping). Unreferenced data is garbage collected. A kind of exception handling is available (essentially try-catch with no filter). Most functionality is provided via C libraries.

      Nice things: The C-to-Lua and Lua-to-C interface is probably best-in-breed (extremely easy to work with, way easier than embedding Python or Perl).

      Interesting things: Native types include number (only one kind, "double" by default), immutable string (binary-safe), boolean, nil, table (hashtable), function (either a Lua function or a C function), and userdata (opaque blobs of data that C code can use). The only data structure is the table. Tables are used to implement structures (map a string member name to a value), arrays (map a number to a value), classes (map a string to a value; functions are values too). Even the set of currently-accessible variables (the environment) is a table.

      Tricky things: While the table is very flexible, it sometimes takes some stretching to make it cover all the cases. You need to learn a number of idioms to be really effective with Lua.

      I've written most of a library in Lua for easy-to-write self-contained apps. It was incredibly easy to use. (Maybe someday I'll actually finish my library...)

      --
      Time flies like an arrow. Fruit flies like a banana.
    6. Re:LUA in WoW by nanosquid · · Score: 1

      Not trying to troll, but in all honesty with tons of other proven languages out there, why did blizzard bank on this one? what makes this language so great?

      Lua was designed as an embedded scripting language, and it's far more "proven" in that domain than other languages: there are dozens of commercial games that use it (probably far more than any other single scripting language). The reason people like to use it is because Lua is really fast, tiny, easy to interface with, easy to embed, easy to package, and easy to learn.

      You can embed Python, Ruby, or Perl, but it's a lot more work and often doesn't work as well as Lua in practice.

    7. Re:LUA in WoW by shutdown+-p+now · · Score: 1
      C and derivatives have one of the least consistent syntaxes out there. About the only thing worse is BASIC.

      As for Lua, it's neither BASIC nor Pascal syntax-like. Syntactically it's probably closest to Modula without semicolons (which is a good thing, very clean syntax), or Ruby for something more modern to compare to. Semantically it's somewhere between Scheme and JavaScript.

    8. Re:LUA in WoW by xouumalperxe · · Score: 1

      Python also plays the "hash table is my primary data structure" game, and some neat tricks can be pulled off from there (minor stuff in selfmodifying code, at least).

    9. Re:LUA in WoW by Anonymous Coward · · Score: 0

      Actually I do a great deal of embedding using Python. I have a C++ class that wraps up everything I need to do/add Python to a new project. It handles everything from setup (can pick-up just adding the necessary things in case it is init'd elsewhere), serializing (functionality for saving the state of the system, giving it back as a byte-stream to save or what-not, restoring, etc...). Also has functionality for pushing across code updates from a server in real-time and loading it up without needing to save them to disk (I made it so my clients are given code to run and calculate so they can return data without needing to persist anything), can also persist as well. Has other functions, probably should release it to the public, except I've noticed most Python users like to 'extend', not 'embed' as I am required to do. Python is actually quite easy to embed, even compared to LUA (I used LUA before, I actually find embedding and using Python from C/C++ easier and faster). A nice bit, people seem to be able to pick up Python quite a bit faster then LUA, hence the main reason I use it.

      All of these other comments around stating that Python is not easy to embed, more difficult to use, etc... have obviously not used both. I embedded LUA for two years, been embedding Python for one year, I find Python easier to use in all regards. If you don't use any binding tools (LUABind, boost::python, any of the other 50 out there) then they are near identical in how they are bound, using tools, again, they are near identical in how they are bound (heck, LUABind, I think it was, *is* boost::python for lua), not to mention that serializing the scriptor state, or parts thereof, is vastly easier in Python, pausing the state in Python at any time is also very simple (I use the stackless version, really needs to be renamed, but it is still simple to do in normal Python), and due to all the features Python is far more useful as a scripting language.

      Personally, for most of my projects (heavy networking and lots of little micro-process orientation), I prefer Erlang, although it is absolutely horrid to use, and not embeddable in any way that I've seen.

    10. Re:LUA in WoW by OvermindDL1 · · Score: 1

      Er, twas me above, didn't take login...

    11. Re:LUA in WoW by Frothy+Walrus · · Score: 1

      Semantically it's somewhere between Scheme and JavaScript.

      also, Kansas is somewhere between Maine and California.

    12. Re:LUA in WoW by shutdown+-p+now · · Score: 1

      Influence of Scheme on Lua design is well documented by the authors themselves. As for ECMAScript, it's really fairly obvious to anyone who has seen both Lua and ECMAScript, that their basic building blocks (Lua tables and ECMAScript extensible objects) are very similar.

  2. Yeah... by phasm42 · · Score: 2, Funny

    These days, Brazil is no longer just on the map for it's fine coffee and martial arts.
    I pretty much stopped reading after that.
    --
    "No one likes working in a hamster wheel, and your shop smells of cedar shavings from here." - TaleSpinner
    1. Re:Yeah... by syphax · · Score: 1, Troll


      That struck me as odd, too. A joke? I always thought Brazil was on the map for the Amazon, Carnaval, and fine women (see: Carnaval). I suppose you can also add ethanol and insane gang and prison violence.

      --
      Simple Unexpected Concrete Credible Emotional Stories
    2. Re:Yeah... by Threni · · Score: 3, Funny

      >>These days, Brazil is no longer just on the map for it's fine coffee and martial arts.

      >I pretty much stopped reading after that.

      Exactly. If theres one thing I cant s'tand its people who dont know how to us'e punctuation.

    3. Re:Yeah... by Eccles · · Score: 4, Funny

      I was thinking of a particular, uh, "haircut" myself...

      --
      Ooh, a sarcasm detector. Oh, that's a real useful invention.
    4. Re:Yeah... by garcia · · Score: 0, Troll

      I always thought Brazil was on the map for the Amazon, Carnaval, and fine women (see: Carnaval). I suppose you can also add ethanol and insane gang and prison violence.

      You forgot hacking.

    5. Re:Yeah... by syphax · · Score: 1

      ... and soccer/football. And free culture (eg Minister of Culture Gilberto Gil)

      --
      Simple Unexpected Concrete Credible Emotional Stories
    6. Re:Yeah... by Knux · · Score: 1

      These days, Brazil is no longer just on the map for it's fine coffee and martial arts.

      There's also corruption, prostitution...

    7. Re:Yeah... by drooling-dog · · Score: 1

      I was going to add "bathing suits, bikini wax, and babes" but it looks like my esteemed colleagues here have beaten me to it...

    8. Re:Yeah... by yoyoq · · Score: 1

      i stopped reading after "These days"

    9. Re:Yeah... by jesterman · · Score: 1

      There's also corruption, prostitution...

      Thank god no such things exist in rest of the world! Oh my, Brazil is soo 'retro'...

    10. Re:Yeah... by Anonymous Coward · · Score: 0

      "for it is fine coffee" is what that apostrophe means...

    11. Re:Yeah... by BorgCopyeditor · · Score: 2, Funny

      I always thought Brazil was on the map to keep South America from looking like a Sea Monkey.

      --
      Shop as usual. And avoid panic buying.
    12. Re:Yeah... by Liquid+Len · · Score: 1

      Parent poster has been unfairly modded as troll. There definitely should be a way to mod down a submission. I mean, come on, a little irony can't hurt but the sentence "These days, Brazil is no longer just on the map for it's fine coffee and martial arts" is outright offensive.
      And no, I'm not from Brazil.

  3. WoW by dsraistlin · · Score: 2, Informative

    It is also the scripting language that is used for WoW mods.

  4. Another scripting language? by spike2131 · · Score: 1

    What advantage does Lua have over perl/python/ruby/other existing scripting languages that makes it worth investing the time to learn?

    --
    SpyDock: Scientific Python in a Docker container
    1. Re:Another scripting language? by Anonymous Coward · · Score: 4, Informative

      It's very lightweight and used in fields where a full language is needed but the overhead of a Perl/Python/Ruby is unacceptable. Plus the 'sole' datatype is pretty flexible (can be used to code OO (prototypical & definition), Modules, namespaces &c.). It's also pretty damn fast, and quite solid for general use. The wikipedia entry has a decent list of games & apps that it's being used in.

      I must agree though that this article didn't do too much in terms of selling the language, which is probably what the book is supposed to do.

    2. Re:Another scripting language? by Jimmy_B · · Score: 4, Insightful

      What advantage does Lua have over perl/python/ruby/other existing scripting languages that makes it worth investing the time to learn?

      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.
    3. Re:Another scripting language? by scorpionsoft · · Score: 1

      IIRC, Lua is the scripting language used for World of Warcraft user interface modifications. A decent practical reason, at least!

    4. Re:Another scripting language? by Anonymous Coward · · Score: 2, Informative

      It's also used to configure damn near everything in Homeworld 2. You can tweak anything with just notepad.

    5. Re:Another scripting language? by Anonymous Coward · · Score: 0

      What advantage does C++, C, Pascal, other programming languages have over machine language that makes it worth investing the time to learn? Let's all go back to learning machine language and if you can't then you are just too stupid to work in Information Technology.

    6. Re:Another scripting language? by daVinci1980 · · Score: 1

      Lua's not bad as a very trivial sort of scripting language, but the problem with it is that you cannot extend it with structures without writing underlying C code.

      That makes it a pretty poor choice to do anything that's fairly complex, because under the covers you're still going to write a significant amount of C. All the flexibility of a scripting language, all the danger of C code is not a place I like to spend my time.

      Lua is a tiny, tiny scripting language, which is pretty cool. However, it also has an equivalently tiny standard library. For the same 181K, I can get python embedded in my application. (I can then add pieces, ala carte, from the standard library).

      Most newer game engines are using python (or something with a very similar featureset) for their scripting needs as opposed to lua.

      --
      I currently have no clever signature witicism to add here.
    7. Re:Another scripting language? by grumbel · · Score: 1

      ### What advantage does Lua have over perl/python/ruby/other existing scripting languages that makes it worth investing the time to learn?

      When it comes to day to day scripting, I don't think its worth to learn, since it just doesn't provide much in that area, its just not what is was build for. What LUA however is very good at is getting embedded in other applications, in that area it just is way superior to perl/python/ruby/etc.

      Its not just a matter of size, but mainly a matter of flexibility, i.e. if you want to run multiple VMs at once (say one for each game object), then you can simply do that in LUA, in other scripting languages you however can't do it at all or only with dirty hacks. The reason is that most other scripting languages are not meant to be embedded, but to run stand alone, their APIs just aren't build with that flexible in mind. Perl/Python/Ruby/etc. are for most part build so that you give control up to their interpreter, while LUA is build in a way that your C code always has full control.

      In a LUA based application you have C code that runs LUA scripts, in a perl/python/ruby/etc. application on the other side you have perl/python/ruby/etc. that runs C code, big difference when you just want to extent an application instead of let the script take over.

    8. Re:Another scripting language? by Luatic · · Score: 1

      check out this benchmark: it'll open your eyes bigtime! (especially if you take in account that the complete language together with it's os, string and math library takes no more than 180k; which makes it a real alternative for embedded solutions)

    9. Re:Another scripting language? by Anonymous Coward · · Score: 0

      > 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.

      Which was exactly what tcl was used for, a decade ago. Whatever happened to tcl?

      I believe it is still embedded in some applications, including many EDA (i.e. chip design) tools.

    10. Re:Another scripting language? by XCondE · · Score: 1

      Not only that but it will compile in any Ansi-C platform without going through all your ./configure procedures. That means you can run it in pretty much any platform (forget i386/risc/etc - I mean those weird processors you never heard of).

    11. Re:Another scripting language? by nanosquid · · Score: 1

      For the same 181K, I can get python embedded in my application.

      Except it won't be Python, it will be Python-without-its-standard-library. And that's pretty much what Lua is, except for minor syntactic differences and the fact that Lua is easier to interface with from C and runs faster.

    12. Re:Another scripting language? by tigersha · · Score: 1

      TCL? The Crap Language? It died a well deserved death.

      --
      The dangers of excessive individualism are nothing compared to the oppressiveness of excessive collectivism
  5. Try out lua - on Nmap by wordisms · · Score: 3, Informative

    Great example of how lua can extend the functionality of a program. Check out the Nmap Scripting Engine.

    With lua and NSE, nmap can now do things like vulnerability testing. Why not download nmap now and give it a try?

  6. Re:The ignorant and SlashDot authorship... by StarfishOne · · Score: 1

    "And that's not even trying..."

    Yeah, you forgot the women. ;)
  7. Supreme Commander by maeltor · · Score: 3, Informative

    Its also used in Supreme Commander, to script a lot of the in game AI and unit actions as well as define the attributes of moddable units.

    1. Re:Supreme Commander by ni1s · · Score: 2, Interesting

      LUA was also implemented in the Freespace 2 engine that was released some years ago to the public. http://scp.indiegames.us/news.php

    2. Re:Supreme Commander by drinkypoo · · Score: 1

      Lua is used within the Half-Life 2 modification "Garry's Mod" to add easy user scripting to HL2.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    3. Re:Supreme Commander by Xzzy · · Score: 0, Redundant

      Add World of Warcraft to the list. You may have heard of it.

      The entire user interface is scripted in lua, which facilitates a huge array of user made customizations.

    4. Re:Supreme Commander by drinkypoo · · Score: 1

      Yes, I heard that wow used it 42 minutes before your comment. But thank you for playing.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    5. Re:Supreme Commander by jorgepblank · · Score: 0

      I heard Far Cry also used it.

      --
      - Jorge Peña
  8. Small? by shmlco · · Score: 2, Insightful

    "Like anything good, it didn't take long for it to be discovered by others looking for a small and efficient scripting language."

    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.

    --
    Any sect, cult, or religion will legislate its creed into law if it acquires the political power to do so.
    1. Re:Small? by Sneftel · · Score: 1

      Ah, but that's the beauty of it. Luiz has shown an incredible resilience against the forces of bloat. IIRC, the language syntax is actually a little simpler now than it was two years ago.

      --
      The opinions stated herein do not necessarily represent those of anybody at all. Deal with it.
    2. Re:Small? by shmlco · · Score: 1

      The "syntax" for PHP isn't that hard either. But that's not where the problem is...

      --
      Any sect, cult, or religion will legislate its creed into law if it acquires the political power to do so.
  9. Is it only for extending things? by parvenu74 · · Score: 1

    After reading over the Lua home page as well as the wikipedia entry, I'm left wondering if Lua is merely a language for writing extensions or if it's intended for building things (like, say, application frameworks?). The other thing I hope someone here can answer is this: are there no other languages designed for extending other applications? Why can't this be done in Ruby or Python or Perl or JavaScript? Not to offend the tens of Lua programmers reading this, but what's the point? What is it that Lua does better than other languages available for the task?

    1. Re:Is it only for extending things? by Nanidin · · Score: 2, Informative

      Speed and size to name a few... it's also easily integrable into C/C++ programs. The second link actually has a long list of Lua benefits.

    2. Re:Is it only for extending things? by a_ghostwheel · · Score: 1

      Ruby/Python/Perl/JavaScript are much more heavy than your average embedded Lua interpreter while still providing decent language feature set. Add to this ease of customization (practically every application that uses Lua as an embedded scripting language, customizes portions of the interpreter), ability to embed not just interpreter but precompiled scripts too and ease of interaction between Lua scripts and C/C++ host program and it becomes product with maybe not large but noticeable market niche.

    3. Re:Is it only for extending things? by ukpyr · · Score: 1

      As you can do almost anything in any language, it's all about ease of task. Ruby is great for writing complex applications in (i've found), where as bash is great for copying some files around to launch an april fools day version of my company's website via cron.

      I find that when I'm writing stuff in ruby, I enjoy it a tad more, than say, perl or php. I've not measured it but I think there is a correlation between enjoyment and efficency. Maybe only in that I get sick of the project I'm working on at a later time than I otherwise would have :)

      From reading some lua in WoW mods and looking at TOME code, I can see why people enjoy it for layering non-compiled configs on top of compiled engines. Just take a look, (TOME is neat as a game anyway) I'm sure you'll see the point soon enough, if not, shake your head and move along to something that does strike your fancy.

      Not sure this is a point other than that, does there need to be?

    4. Re:Is it only for extending things? by Anonymous Coward · · Score: 0

      (1) It's one of the fastest scripting languages (i.e. run time stuff)
      (2) It's small (see above) you can fit the compiler/interperter/runtime in 150 K
      (3) It's thread safe, runs just fine in multiple threads (it has no embedded threading like Perl or Python)
      (4) Works really great in embedded systems for reasons 1-3.

    5. Re:Is it only for extending things? by grumbel · · Score: 1

      ### Why can't this be done in Ruby or Python or Perl or JavaScript

      Can't say about all of them, but most of them only allow you a single VM, which just isn't good enough when you want to keep your scripts apart from each other and secure (i.e. in a game a users script shouldn't crash the engine or change the behavior of other unrelated scripts). In Lua on the other side you can have as many VMs as you want and you never run the risk that any scripts breaks out of its little sandbox. You might be able to replicate that effect in other languages, but in Lua its simply the normal way of doing things, while in other its either impossible or requires lots of extra effort.

    6. Re:Is it only for extending things? by obarel · · Score: 1

      I have used Lua successfully on an embedded platform for demos. It would take a day or two to write a demo from scratch once we got the infrastructure.

      I've used the same infrastructure on WinCE and on OMAP without any modifications (other than pushing the GUI into the WinCE).

      I couldn't have done it with python+tk/tcl in the same amount of time.

    7. Re:Is it only for extending things? by peterpi · · Score: 1

      Others have mentioned the speed and size benefits. Although it's fair to say that it is niche, within that niche it is completely dominant. It's the default choice in the games industry for the sort of code that is not best done in C (or even; not best done by a programmer).

      Let's say your're working on the PSP. You've got 24MB to start with. Take away 4MB for the executable and static data, 5MB for your core geometry & textures (player, car, whatever.) 2MB for sound, half a meg or so for display lists; Before you've even started doing anything you're almost into single figures. In this situation Lua fits just fine. Anything else is a squeeze.

      Also; it's just really nice to work with from the viewpoint of a games coder. For example, when you create a new runtime with lua_newstate, you pass in a callback for memory allocation. How beautifully C! No inhereted, templated classes, no overdesigned 'CLuaManager' rubbish, it's just lovely. From having never used it before, I had it compiled, linked and running scripts in a particularly pleasant and easy afternoon.

    8. Re:Is it only for extending things? by lahvak · · Score: 1

      are there no other languages designed for extending other applications?

      Yes, about zillion od them. My impression is that lua is more powerful than s-lang, easier to learn than scheme, and smaller and more portable than ruby/python/perl.

      --
      AccountKiller
    9. Re:Is it only for extending things? by nanosquid · · Score: 1

      I'm left wondering if Lua is merely a language for writing extensions or if it's intended for building things (like, say, application frameworks?).

      It's primarily intended for writing extensions. That is, a little bit of scripting and configuratino that goes into a big C/C++ program.

      The other thing I hope someone here can answer is this: are there no other languages designed for extending other applications?

      Tcl/Tk was also designed for this purpose, but doesn't work as well. S-Lang is another choice.

      Why can't this be done in Ruby or Python or Perl or JavaScript?

      You can embed Ruby, Python, Perl, or JavaScript, and sometimes that makes sense. However, those languages and their implementations aren't primarily designed for embedding. For example, you can trivially embed Lua in a self-contained executable, but if you embed Python, you will probably have to ship some Python library functions with it, plus the installers and path management necessary to support that. Documentation and security are also much easier for embedded Lua.

    10. Re:Is it only for extending things? by Anonymous Coward · · Score: 0

      You can embed ... JavaScript, and sometimes that makes sense. However, those languages and their implementations aren't primarily designed for embedding.

      In future, please think before you open your mouth.
    11. Re:Is it only for extending things? by Anonymous Coward · · Score: 0

      You should heed your own advice.

      Javascript runs embedded in browsers; it's specialized for that purpose and doing anything else with it, like embedding it in a new application, is a major pain. Among the languages I named, Javascript is probably the worst choice for embedding right now.

      I hope that will change in the future, since lots of people know Javascript and it's a pretty reasonable language. But for the time being, it's a bad choice for embedding.

  10. Neko by Anonymous Coward · · Score: 0

    Neko's API is much more easier to use. What exactly does Lua have that Neko doesn't?

    1. Re:Neko by Anonymous Coward · · Score: 0

      Well like ruby on rails, you get Neko in Case - Lua doesn't have anything to offer in streamlined drop programming ;)

  11. Re:The ignorant and SlashDot authorship... by Anonymous Coward · · Score: 1, Funny

    He didn't forget: he's a /. nerd, so clearly women never entered his mind.

  12. Re:The ignorant and SlashDot authorship... by p3d0 · · Score: 1

    Yeah, I agree. That was lame, lame, lame.

    --
    Patrick Doyle
    I mod down every jackass who puts his moderation policy in his sig. Oh, wait a sec....
  13. Insane gang and prision violence?? by Anonymous Coward · · Score: 1, Insightful

    You mean just like the US of A??

    1. Re:Insane gang and prision violence?? by Anonymous Coward · · Score: 0

      Score:5, Tu Quoque

  14. I'm sure I'm not the only one to point it out, but by MyIS · · Score: 2, Informative

    What's with the "base index of 1" array conventions in their standard library?

    I love Lua, and have played around with it quite a bit, but that part of their specs always annoyed me. Interestingly, it is flexible enough to allow custom "standard lib" code that uses base index of zero. Also, custom scriptable objects can define their own conventions, including relying more on the iterator interfaces, which forces things to be theoretically cleaner.

    But still, just having that even as a possibility irks me.

    --
    http://zero-to-enterprise.blogspot.com/
  15. Re:The ignorant and SlashDot authorship... by vivaoporto · · Score: 4, Insightful

    As a Brazilian, I can say you are really not trying.

    Mardi Gras?

    There is no such thing in Brasil. I guess you mean carnival, it differs from mardi-gras in the ammount of naked people (and crossdressers).

    Nazi hideout?

    I think you confused Brazil with Argentina. 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).

  16. when they say "lightweight"... they mean it by FooAtWFU · · Score: 5, Informative
    You use Lua for your in-game scripting of your computer games. Can you fit your Perl/Python/Ruby interpreter in 150 kilobytes? I didn't think so. Can you get it under a MIT license? I don't think you can.

    Should you use it for your online web application backend, or your system administration scripts? Probably not.

    --
    The World Wide Web is dying. Soon, we shall have only the Internet.
    1. Re:when they say "lightweight"... they mean it by winkydink · · Score: 2, Insightful

      I believe I can get perl under the Artistic License. How does the MIT license differ in a way that is advantageous?

      --

      "I'd rather be a lightning rod than a seismometer." -Ken Kesey

    2. Re:when they say "lightweight"... they mean it by SanityInAnarchy · · Score: 1

      Can you fit your Perl/Python/Ruby interpreter in 150 kilobytes?

      Does it matter?

      Here, let me fix this for you:

      You use Lua for your in-game scripting of your computer games which are written in statically-compiled languages.

      If the game had been written in Perl/Python/Ruby in the first place, no additional scripting language would be needed. Granted, Python is probably the only one of those that's reasonably fast enough, but still...

      --
      Don't thank God, thank a doctor!
    3. Re:when they say "lightweight"... they mean it by acidrain · · Score: 2, Informative

      Did you just get modded up for not being able to type "MIT license" into google?

      MIT is BSD-style without any clause that would stop it from being re-used in a commercial product. And sorry guys, this is a requirement for use in games right now.

      --
      -- http://thegirlorthecar.com funny dating game for guys
    4. Re:when they say "lightweight"... they mean it by Anonymous Coward · · Score: 0

      Has anyone gotten LUA to work on a Linksys router with DD-WRT or something like that?

    5. Re:when they say "lightweight"... they mean it by nanosquid · · Score: 1

      If the game had been written in Perl/Python/Ruby in the first place, no additional scripting language would be needed.

      True, but there are often reasons for not doing that.

      Does it matter?

      The fact that Lua fits into 150kbytes doesn't matter that much, but the fact that it has no external dependencies (script libraries, etc.) is often crucial. In many applications, it's also important that its standard library is minimal, i.e., that it does not have a lot of built-in functionality.

    6. Re:when they say "lightweight"... they mean it by SanityInAnarchy · · Score: 1

      True, but there are often reasons for not doing that.

      I'm not convinced of that. Until very recently (until people started actually thinking about 64-bit gaming), Python looked like a very real possibility. Almost fast enough, can be extended with C (and thus Assembly) for the few cases where it's not, and I believe there are ways to compile it to an EXE.

      --
      Don't thank God, thank a doctor!
    7. Re:when they say "lightweight"... they mean it by Anonymous Coward · · Score: 0

      Yes.

    8. Re:when they say "lightweight"... they mean it by dkf · · Score: 1

      You use Lua for your in-game scripting of your computer games.
      A potential competitor here is Tcl, which, like Lua, has an embedding background.

      Can you fit your Perl/Python/Ruby interpreter in 150 kilobytes? I didn't think so.
      You can't fit Tcl into that space either these days. But you do get more functionality out of the box, and it's trivial to profile that functionality for specific application usage too (very useful for embedded use).

      Can you get it under a MIT license? I don't think you can.
      Tcl uses the advertizing-free BSD license, which is well-known to play well with others.

      Should you use it for your online web application backend, or your system administration scripts? Probably not.
      Agreed. Lua's base functionality is just too sparse for that sort of use, and it's not a market segment that the language ever addressed. But Tcl (especially with one or two extensions) does very nicely in that space. And many others too.
      --
      "Little does he know, but there is no 'I' in 'Idiot'!"
    9. Re:when they say "lightweight"... they mean it by Anonymous Coward · · Score: 0

      True, but there are often reasons for not doing that.
      I'm not convinced of that.

      So, you're saying that there are NO reasons not to write a game in Python, and therefore anyone who writes a game in any other language is WRONG. Care to back that up, or are you just a drooling fanboy?
    10. Re:when they say "lightweight"... they mean it by winkydink · · Score: 1

      There is nothing in the Artistic license that prohibits commercial use.

      --

      "I'd rather be a lightning rod than a seismometer." -Ken Kesey

    11. Re:when they say "lightweight"... they mean it by SanityInAnarchy · · Score: 1

      True, but there are often reasons for not doing that.
      I'm not convinced of that.
      So, you're saying that there are NO reasons not to write a game in Python

      No, I'm saying that there are reasons, but they don't often apply when people think they do. We could start by you telling me which reasons you endorse for using another language...

      (And no, I'm not a drooling Python fanboy. In fact, I hate Python. Perl6 looks better, but there are things I hate about it, too, and it's not even out yet. I just am not enough of a masochist to use C/C++/C# if I can possibly avoid it.)

      --
      Don't thank God, thank a doctor!
    12. Re:when they say "lightweight"... they mean it by Anonymous Coward · · Score: 0

      You're not getting it. You seem to think that the only determinant of which language to use is how "good" or "powerful" or "fast" it is. In fact, in real life, those rarely have anything to do with picking a language.

    13. Re:when they say "lightweight"... they mean it by cpeterso · · Score: 1

      Games are performance-critical. At least Lua code compiles down bytecode. Tcl is interpreted. Even Tcl numbers are strings.

  17. And it won't take too long by Colin+Smith · · Score: 1

    to turn it into a bloated monstrosity because it would be so much more useful if it just did this one tiny little additional thing.

    --
    Deleted
    1. Re:And it won't take too long by Anonymous Coward · · Score: 0

      Actually, Lua tends to get less features with each version. The authors remove features and replace them with simpler, more powerful ones.

  18. Re:The ignorant and SlashDot authorship... by niloroth · · Score: 1

    Yeah, the soccer was a definite miss, but for those of use who think a work out is more than just moving a desktop from one cubicle to another, brazilian ju-jitsu is not only a great workout, but one of the best and most usable martial art out there. I would say that with the rise of MMA in this country, more Americans would relate BJJ with Brazil than soccer.

    (yes, this is an Americentric post)

    --
    09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
  19. It is extremely easy to embed. by pavon · · Score: 4, Insightful

    If you want to add scripting functionality to an existing application Lua is by far the easiest way to do so, and it has an added benifit being more efficient (both in terms of memory consumption and execution speed) than python or ruby. It is fairly easy for power-users to learn, as it is simular to javascript in many ways, and yet is also powerfull, as it is a complete functional language. For these reasons, you are seeing it being used more and more in open source desktop applications as well as many big name games such as WoW.

    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.

  20. Cue the toilet humor by rrohbeck · · Score: 2, Insightful

    >'Lua' means 'moon' in Portuguese and is pronounced LOO-ah.

    I guess all the Americans here didn't get it.

    1. Re:Cue the toilet humor by drinkypoo · · Score: 1

      I'd guess that most of the Americans here know that while we call our toilets John, you backwards brits call them Lou.

      --
      "You're right," Fisheye says. "I should have set it on 'whip' or 'chop.'"
    2. Re:Cue the toilet humor by alienmole · · Score: 1

      Huh. That sounds a bit potty to me.

    3. Re:Cue the toilet humor by nani+popoki · · Score: 1

      Actually, "lua" *is* the word for toilet (or any other kind of pit) in Hawaiian.

  21. Martial Arts? by Anonymous Coward · · Score: 0

    Brazil is famous for martial arts? WTF?

    1. Re:Martial Arts? by Anonymous Coward · · Score: 0

      Brazilian Ju-Jitsu and Capoeira

  22. YAML versus XML or JSON by goombah99 · · Score: 1

    Asking what Lua has over Perl/python is like asking what YAML has over XML. You can do more in XML but it's not a lightweight format. YAML is clean and human readable, and fast to parse. It's so lightweight that I actually use it in my Python program to define complex structures of constants, since it's actually a cleaner syntax than the python code itself!

    Indeed there are extremely few XML applications I have seen that would not be much better served by YAML. for example, .plist files on macs ought to be YAML. this would make a much better bridge between unix flat file configs and the desired database style configs that .plist achieve. (On the other hand things like markup languages for complex text layout are apropos for XML. my point is very few places benefit from XML.)

    So the analogy here is that sometimes simpler is more useful than full featured. the trick is getting the most out of the least, not simply removing features from the complex form. Besides which To the extent that YAML is turing complete it's as good as anything else. Just as YAML can in principle represent anything that XML can.

    --
    Some drink at the fountain of knowledge. Others just gargle.
    1. Re:YAML versus XML or JSON by billcopc · · Score: 1

      Finally someone with a brain! I thought I was the only guy who sees XML for the bloated non-solution that it is! Of course, the internets love acronyms (see AJAX). Personally, I prefer fast and lean binary encoding (with complete documentation of its structures) but all these late generation programmers are allergic to anything that existed before 1998 :P

      --
      -Billco, Fnarg.com
    2. Re:YAML versus XML or JSON by Anonymous Coward · · Score: 0

      No, you're kinda late to the party. Pretty much everybody who isn't a Java weenie has given up on XML and the overly-complex formats/specs that surround it except in the places where it's already thoroughly entrenched (we're kind of stuck with RSS and Atom, for example).

    3. Re:YAML versus XML or JSON by TuringTest · · Score: 1

      I prefer fast and lean binary encoding (with complete documentation of its structures)

      You put that in parentheses as a secondary characteristic, but that's the very distinguishing reason why XML was invented. You're not supposed to need complete documentation for using a XML file format, they should mostly self-documenting - it was designed as a flexible format for interchange. Binary and XML are for different goals, you preferring one over the other is like saying that you prefer cars over railways because they're oh so easier to park in your garage.

      Problem is not that XML is bloated, is that it's being used for something it was not intended. But thanks to its desirable property of having universal parsers now it's being used elsewhere. Before 1998 you'd have to build your own parsers for every file format using yacc or bison, today you can reuse code - even when it's not be the best solution. But you can't blame programmers for following the path of least resistance.

      --
      Singularity: a belief in the "God" idea with the "demiurge" relation inverted.
    4. Re:YAML versus XML or JSON by billcopc · · Score: 1

      Yep... XML parsers are everywhere, and they're mostly slow and resource-intensive because XML is often the bluntest tool for the kind of tasks it's applied to. XML indeed is a merging of data and structure, and that's precisely what irks me about it. The structure is repeated for every data record in the file. There is so much redundancy that it's nauseating to a tweak freak such as myself. The fact that it compresses well doesn't excuse the bloat.

      Way back when XML was "the next big thing", I instinctively assumed it was an open data interchange format, the kind you would use to migrate databases from MySQL to Oracle or whatever. I never thought people would use it for every asinine little chore, in places where readability is pointless and platform neutrality is not required. XML is a human format, computers are not humans, the tags just get in the way. Now instead of doing a simple fputs/fgets into a data structure, you have to run the thing through a heavy-duty parser that takes a thousand times longer to decipher the mess. How is that an improvement ? Sure, the data is human-readable but humans don't process it, computers do.

      --
      -Billco, Fnarg.com
  23. LUA in games by mkithara · · Score: 2, Informative

    It's also the scripting language used by Supreme Commander.

    1. Re:LUA in games by Anonymous Coward · · Score: 1, Informative

      It is also is heavily used in Adobe Lightroom.

      When asked how to get ready for the upcoming Lightroom SDK, an Adobe engineer said "Go hack WoW and come back when we have the SDK ready."

    2. Re:LUA in games by koxkoxkox · · Score: 2, Interesting

      Lua is not only used in games.

      As another example of what you can do with Lua, it is used in Ion, a window manager (http://modeemi.fi/~tuomov/ion/). Granted, it is a little known window manager, intended for people who dislike mouse and fancy graphic effects, but it has been designed to be a lightweight solution and that's why Lua had been chosen.

      http://www.yzis.org/ uses it also.

  24. Re:The ignorant and SlashDot authorship... by Anonymous Coward · · Score: 0

    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).

    MMA is pretty popular in the states. Pre-MMA days, the first things I thought of when I heard Brasil was the Soccer team and hot women. Now I think of BJJ first, because BJJ was just that dominant in the early UFCs. As for martial artists not knowing BJJ outside of MMA, I have an article about Helio Gracie being in the longest fight ever from a Karate magazine around 1990, before the first UFC in America. I have to admit, I had no idea what to think when I read it as a kid, other than it had to be a boring fight. :)

  25. Re:The ignorant and SlashDot authorship... by Chysn · · Score: 1

    ...plastic surgery...

    --
    --I'm so big, my sig has its own sig.
    -- See?
  26. Re:The ignorant and SlashDot authorship... by hampton · · Score: 2, Insightful

    Don't forget waxes!

  27. Step up to Lua by Anonymous Coward · · Score: 1, Insightful

    Having spent many years with Perl, then Python, and finally Ruby, I discovered Lua recently at v5.1, and *love* the language. Lots of people already mentioned that it is used heavily as an embedded language, but, it was designed as an 'extensible' language, lending itself to creating DSLs with ease. One of the fastest scripting languages, it is also one of the smallest: the whole distribution fits on a floppy disk (if you still use those).
    Although there is good progress with the Kepler project, there is not yet a sparkly project like 'Rails' that actively promotes the language.

    1. Re:Step up to Lua by Anonymous Coward · · Score: 0

      Ah that explains it. I don't use floppy disks anymore, needed 4 DVD's just to store "helloworld.lua"

  28. Lua works on Lego robots by EmbeddedJanitor · · Score: 2, Informative
    Lua works on Lego robots http://www.hempeldesigngroup.com/lego/pbLua/

    Java does too http://lejos.sourceforge.net/

    I don't think there are python or ruby ports though, possibly because these devices are very limited.

    --
    Engineering is the art of compromise.
  29. Re:The ignorant and SlashDot authorship... by Anonymous Coward · · Score: 0

    There are other things that Brazil should be known for...

    1.) They are the nicest people one would ever want to meet, with qualities rarely found in North America such as humility, and spontaneous warmth and friendliness.

    2.) They make excellent beer.

    3.) Massive government corruption... In spite of the fact that perhaps up to two thirds of all politicians at all levels of government are corrupt, Brazilians vote them back into power time and time again. Though Brazilians can always get up a crowd to demonstrate against George Bush (who has nothing to do with this), they couldn't get off their butts to protest or demonstrate against their own corrupt leaders. They rather just complain about it and pretend that this is something beyond their control. Fiscal waste and corruption alone must be costing their GDP a good 20 percent.

    4.) Brazil is totally inept at conserving its nature preserves and forests. Often there has been illegal cutting on grand scale in some forest reserve for a decade before arrests are made. Entire river systems with millions of fish are wiped out in an instant after some toxic spill. Thousands of fishermen become unemployed overnight, and people who depended on the fishery are suddenly starving and depending on handouts, but the perpetrator is never caught.

    5.) Their justice system simply doesn't work very well. It takes so long to receive justice that people grow old and die before receiving fair compensation. The crooked politicians seem to never actually end up in jail. Criminals who commit heinous crimes serve little time before they are out again on holiday passes, then disappear.

    6.)Oh - did anyone mention the beautiful women?

  30. Re:The ignorant and SlashDot authorship... by Anonymous Coward · · Score: 0

    It also has a VAST disparity of wealth between an elite upper class and an utterly destitute lower class.

  31. Re:I'm sure I'm not the only one to point it out, by CastrTroy · · Score: 3, Informative

    If you look at languages like C then having an array start at 0 makes sense, because the array index is the offset from the beginning of the array. However, if you don't have pointers, it's really unintuitive to have arrays starting at 0.

    --

    Anthropic principle: We see the universe the way it is because if it were different we would not be here to see it.
  32. Lua's got people using it? by trimbo · · Score: 1

    We've learned over and over on this board that there's only one litmus test for a language's commercial success: whether people are adopting it and using it for business, NOT academic, purposes. Lua has been in the mainstream for game scripting for some time now.

  33. Some thoughts on Lua by ballmerfud · · Score: 2, Informative

    I got on the Lua bandwagon last year, and for what it is designed to do, it is quite good.

    Before I start cheerleading, some comments on the book. Beginning Lua Programming (BLP) is a very good book on the subject, especially for people new to Lua or perhaps even to programming. I own this book as well as the "Programming in Lua" (PIL) book by Roberto Ierusalimschy, the latter of which I think has some of the best technical writing I've seen in a computer book and is on par with the likes of the late W. Richard Stevens. The two books are both very good, but I think serve slightly different audiences. BLP is a comprehensive book filled with gradual, well thought-out examples that can pretty much lead anyone through Lua regardless of programming experience, and help them to learn it well. The PIL book is written for more experienced/professional programmers who don't need as much hand holding.

    Despite being a small language, Lua sports some serious language features, and you will be sorry not to learn them all. This is where the two books differ I think. PIL assumes at least a nodding acquaintance with concepts such as closures, iterators, generators, and more advanced concepts such as its coroutines (which are a somewhat extended form of blocks in Ruby). If you are not familiar with these, BLP will ensure that you come away with a full understanding through a battery of examples and patient prose.

    That said, people who are already familiar with the above (through prior experience with languages such as Ruby or Python, for example) might find BLP a little slow. This is where PIL really shines. PIL is an extremely well-written book by the Lua's principle architect which provides a full treatment of the language in an economy of pages. It is hard to believe when reading the text that English is the author's second language. The examples are all very good, well chosen, but not excessive. The book moves at a steady pace and covers the same ground in much less space than BLP. One place where PIL really shines is on covering the C API and C programming aspects of Lua. In this respect, it is clearly superior to BLP. But again, you have to be a well-grounded C/C++ developer to appreciate this.

    As I said, I own them both. I read PIL first which got me embedding Lua in C applications in no time, and then went back and read BLP to round out and sharpen my skills in the language proper. I think the books can complement each other in this way. They are both above average books.

    And now for those who have not used Lua and wonder why they would want to. Lua is a tiny, standalone language/interpreter that can be put almost anywhere. It is an ideal way to extend your application as the entire language and libraries fit into a single library under 200Kb in size. It is written in ANSI C and is extremely portable. In my opinion, Lua is not a language you would choose instead of Ruby or Python (unless of course you were already very proficient at it), as I think those languages have much more to offer in either syntactical elegance or extensive standard libraries. Lua's function as a language is very similar to SQLite's function as a database. It's a powerful little multitool you can use to dramatically enhance and extend your applications with very little effort. A feature that might take 3,000 lines of C might take 10 lines of Lua. My experience with it so far has been very positive, and it has pretty much become a staple in my programming repertoire. It is the ultimate compact domain specific language.

    --
    http://uncyclopedia.org/wiki/User:Steve_Ballmer
  34. Too heavy... by frank_adrian314159 · · Score: 1

    The syntax is just way too overblown - but then us Smug Lisp Weenies know that anything more than parens and a few lexical markers is overblown.

    --
    That is all.
    1. Re:Too heavy... by rubycodez · · Score: 0, Flamebait

      yup, that link shows what the problem is with LISP. In ivory tower theory, a beautiful and indeed the most powerful possible computer language. In practice, the real world implementations that people can get and use suck, especially CL. Sad really.

    2. Re:Too heavy... by Anonymous Coward · · Score: 0

      Bah, LISP has *way* too much lexical structure for a Forth purist... whitespace as token separator is all we need :)

    3. Re:Too heavy... by lahvak · · Score: 1

      ? of speak you that "S parens" those are What

      --
      AccountKiller
    4. Re:Too heavy... by Anonymous Coward · · Score: 0

      Lisp, you mean the language where they decided
      that "why write a parser when the programmer's
      brain can dot it for me ?" ?

  35. Adobe Lightroom by Anonymous Coward · · Score: 0

    btw, A big chunk of Adobe Lightroom's UI was written in Lua. You can google for more information.

  36. Re:The ignorant and SlashDot authorship... by Anonymous Coward · · Score: 0

    Wrong...many Nazis went to Brazil.

  37. Re:The ignorant and SlashDot authorship... by glwtta · · Score: 1

    the ammount of naked people (and crossdressers)

    Doesn't that make them cross-undressers?

    --
    sic transit gloria mundi
  38. Re:The ignorant and SlashDot authorship... by StarfishOne · · Score: 1

    Hmm, that's one point of view.. another one is that nerds have to keep track of ALL variables. :D

  39. Re:The ignorant and SlashDot authorship... by yorugua · · Score: 1

    and of course, being this slashdot, we will of course mention Brazil and recall it maybe by its coffee or Football/soccer, but not because of brazil's mulatas/garotas....

  40. It's an embedded data-description language by Dutch+Gun · · Score: 1

    There are two things that make Lua different/better than existing scripting languages, IMO:

    1) It's designed to be embedded in applications.
    2) It's a data-management language.

    Other languages can be embedded, but it's harder to do (at least when I last looked), and I have yet to see an embedded language as lightweight as Lua with equivalent features. It also has the advantage of being a self-describing human-readable data format (plain-text), but it has an advantage that it's ALSO a language. While all languages worth their salt can embed data, Lua is *designed* around this feature. The use of tables as a built-in data type is key here.

    If you like, you can think of Lua as a more flexible XML, an easily embedded scripting language, or some combination of both.

    --
    Irony: Agile development has too much intertia to be abandoned now.
  41. Re:I'm sure I'm not the only one to point it out, by metamatic · · Score: 1

    Indexes starting at 0 might be unintuitive to people who aren't programmers, but it gets rid of a lot of +1s and -1s in your source code.

    --
    GCHQ Quantum Insert installed. If only our tongues were made of glass, how much more careful we would be when we speak
  42. Re:The ignorant and SlashDot authorship... by Anonymous Coward · · Score: 0

    It is not even known by it's Martial Arts

    Umm, Capoeira?

    http://en.wikipedia.org/wiki/Capoeira/

  43. Re:I'm sure I'm not the only one to point it out, by Anonymous Coward · · Score: 1, Informative

    > However, if you don't have pointers, it's really unintuitive to have arrays starting at 0.

    Tell that to the modulo function. Or pretty much _any_ kind of index arithmetic. Would you rather do 28*i+7*j+k to do a mapping of threedimensional indices to one-dimensional, or 28*i+7*j+k-35? What about backwards?
    k = n mod 7
    j = (n div 7) mod 4
    i = n div 28
    or
    k = 1+((n-1) mod 7)
    j = (((n-1) div 7) mod 4) + 1
    i = ((n-1) div 28) + 1
    ?

  44. Re:I'm sure I'm not the only one to point it out, by Doctor+Memory · · Score: 1

    if you don't have pointers, it's really unintuitive to have arrays starting at 0 Not really, I typically find that when calculating an offset into a 1-based array, I have to add one to whatever offset I come up with to compensate for the base. Using zero-based arrays tends to result in more natural solutions.
    --
    Just junk food for thought...
  45. Re:I'm sure I'm not the only one to point it out, by PresidentEnder · · Score: 1

    I wondered this myself, learning Java. Since Java abstracts from memory and hides pointers from us, why do array indices start with 0? However, building Tetris, I became very glad of this. (Think about the position of the blocks). I'm sure there are other reasons it makes sense....

    --
    I used to carry a bottle of whiskey for snake bite. And two snakes. -Nefarious Wheel
  46. Some examples of what it's good for by Anonymous Coward · · Score: 4, Informative

    Lua's C API is rather stellar. It makes it very easy to jump between Lua and C code near-infinitely, to access C functions from Lua and Lua functions from C, often nested multiple times that way.

    It's also extremely small in terms of memory size and footprint, making it ideal for some embedded applications. I've used it to create a (yes, really) AJAX-enabled web-UI for configuring small Linux boards.

    I had to write some sqlite bindings for Lua to do it (sorry, closed source, GRRR) but it really wasn't even remotely hard.

    On the downside, most Lua projects start to feel like Lisp as you start to add your own language support for things that aren't in the core, and it's best to avoid the object/module support -- that's rather hairy stuff.

  47. YANSL by sycodon · · Score: 1

    Another scripting language to do what the other bajillion could do with a few libraries.

    AHHHHH! When will it end!?

    --
    When Fascism comes to America, it will call itself Anti-Fascism, and tell you to give up your guns.
    1. Re:YANSL by Anonymous Coward · · Score: 1, Interesting

      When will it end? When we stop having every language out there devolve into the same old 'kitchen sink' of a language surrounded by a massive standard library with every possible feature around. Lua is nice as it seems to have resisted this bloat so common in OSS language projects. Some of us occasionally just want the language, and don't care about a language built to support every possible feature that every programmer out there might want.

    2. Re:YANSL by NuShrike · · Score: 1

      Sounds like Lua is more Free Software than OSS.

    3. Re:YANSL by Anonymous Coward · · Score: 0

      You mean that adding libraries to other scripting languages can actually make them smaller? Now that's impressive!

  48. The problem with lua... by Anonymous Coward · · Score: 1, Informative

    Lua is a great little language, unfortunately the runtime changes drastically between versions. While this keeps it small, powerful and fast (especially Mike Pall's luajit) it means your apps are going to have a limited lifespan on supported runtime.

    If the developers could at least maintain ABI stability so library bindings work between versions then we'd see lua gain serious traction outside of gamedev. The luajit gives mono a run for it's money in shootouts, and register based VMs are better suited to dynamic languages.

  49. Re:The ignorant and SlashDot authorship... by obarel · · Score: 2, Funny

    ... Brazilian Jiu Jitsu exists (we in Brazil don't call it that, we call it only Jiu Jitsu).

    Obligatory Simpsons' quote:

    Homer: I have a bladder the size of a Brazil nut.
    Taxi Driver: We just call them nuts here.

  50. What? by RoboStone · · Score: 1

    How could you all forget about Garry's Mod? Basically a bunch of in game mods are built from Lua along with custom weapons and tools.

    1. Re:What? by Anonymous Coward · · Score: 0

      Garry's mod was great, but ever since it split into 2 different versions, I've kind of lost interest(althought i did buy it). No one ever hosts any onslaught-type maps anymore, and what ever happened to buildfortwars, that was probably the best mod, or *mini-mod* i've ever seen for HL2.

  51. garrys mod by DuroSoft · · Score: 0

    Lua is also used in garry's mod (Valve Source Engine physics sandbox mod)

  52. Why bother? by SanityInAnarchy · · Score: 1

    It's embedded. Thus, any features you want to add, you'd add to your main app and call them from within Lua.

    --
    Don't thank God, thank a doctor!
  53. The Important Question is by johansalk · · Score: 1

    What advantage does Lua have over Scheme?

    1. Re:The Important Question is by alienmole · · Score: 1

      One advantage over Scheme is ease of integration with C/C++, both due to the lightweight implementation, and the lack of full continuations. Also, a syntax that doesn't scare your average programmer.

      A stripped-down Scheme which offered a one-shot alternative to Scheme continuations, more like Lua's coroutines, might help. To compete with Lua, it would also need to be implemented as a bytecode interpreter. Existing Schemes like MzScheme and Guile are relatively heavyweight. TinyScheme isn't bytecode-based, afaik. SIOD is outdated and messy. So, Lua can be a pretty rational choice, although I'd definitely go for Scheme if I wanted a more full-fledged language.

    2. Re:The Important Question is by BlueCollarCamel · · Score: 1

      A shorter name.

      --
      1&1 - Cheap domain and web hosting.
    3. Re:The Important Question is by reaper · · Score: 1

      (((Less) lexical) clutter) and (you (can (add, two))) things
      with (an, addition, operator)

      --
      - Dan
    4. Re:The Important Question is by Anonymous Coward · · Score: 0

      One advantage over Scheme is ease of integration with C/C++


      Check out Chicken Scheme, which makes it really easy for Scheme functions to call/access C/C++ functions/objects and for C/C++ to call Scheme functions and access Scheme objects. The Chicken Scheme compiler emits C/C++/Objective-C which can be fed into gcc for any 32 or 64 bit architecture. It has full first class continuations. It doesn't solve your "scary syntax" problem, but that's what preprocessors and hygienic macros are for.
  54. Lua's not new by Anonymous Coward · · Score: 0

    And what's with the "it didn't take long" nonsense? Lua isn't exactly new ya know.

  55. Explanation of "Fitting into the Lua Community" by Anonymous Coward · · Score: 2, Insightful

    >> Small and efficient? Sure, for now. But wait until the rest of the OSS community gets done with it.

    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.

  56. As usual, if you want lightweight and featureful.. by alispguru · · Score: 2, Interesting

    Can you fit your Perl/Python/Ruby interpreter in 150 kilobytes?

    No, but SIOD fits into 75K, has a track record with the Gimp and game extension, and has a use-it-any-way-you-want license. I've used it for web-related stuff and sysadminish things, too.

    --

    To a Lisp hacker, XML is S-expressions in drag.
  57. Aircraft? by mangu · · Score: 2, Informative
    Mardi Gras? Nazi hideout? Amazon rainforest? Soccer?


    One should add to that that Brazil has one of the largest aircraft manufacturers in the world. Embraer started in 1969 as a federal government owned company and was privatized in 1994. Although they had some technology transfer contracts with foreign companies in the past, their current lineup of airplanes has been totally developed in Brazil.

    1. Re:Aircraft? by Anonymous Coward · · Score: 0

      Not to mention the largest amount of stupid and idiots in politics. If not plain liars and thief's...

      But we have some good stuff:
      - world largest football stadium
      - world largest Orkut community
      - world largest hydroelectric plant
      - world largest football fan club FLAMENGO !!!
      - world largest helicopter amount in Sao Paulo

  58. Re:The ignorant and SlashDot authorship... by bill_mcgonigle · · Score: 1

    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).

    When I read the intro I first thought of Capoeira. Is it part of the culture in Brazil, or just well advertised here in the States?

    --
    My God, it's Full of Source!
    OUTSIDE_IP=$(dig +short my.ip @outsideip.net)
  59. Chosen for pdftex successor by WillAdams · · Score: 1

    Appropriately enough called ``LuaTeX'':

    http://www.luatex.org/

    Makes easy a lot of things which had required some bizarre texniques.

    William

    --
    Sphinx of black quartz, judge my vow.
  60. Also in Relic games by Anonymous Coward · · Score: 0

    Such as Company of Heroes, Dawn of War, Homeworld.

  61. Other games too by MouseR · · Score: 1

    The vendetta-online space MMORPG also uses Lua at it's core.

  62. Re:LUA in WoW: it is used in Adobe Lightroom, too by Anonymous Coward · · Score: 0

    Adobe uses it too, in Lightroom

  63. Used in ion by swarsron · · Score: 1

    Lua is used in ion3 (a window manager). It's very easy to learn if you're already experienced in a programming language and is quite powerful (most people here probably wished at one time for the possibility to use code in some configuration file)

  64. Re:I'm sure I'm not the only one to point it out, by Sique · · Score: 2, Insightful

    It has to do with two very basic properties of natural numbers: Cardinality and Ordinality.
    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.

    --
    .sig: Sique *sigh*
  65. Re:The ignorant and SlashDot authorship... by Guy+Harris · · Score: 1

    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).

    I might be missing something, but I've yet to see the name "Embraer" in any of these threads.

  66. rebol pros and cons and Lua by Budenny · · Score: 1

    Why would you go to this rather than rebol? Which seems to have the advantage of offering easy to make guis as well. Whereas for a user interface don't you have to go to something like murgalua with Lua? Or are there other short cut gui designer environments for Lua?

    1. Re:rebol pros and cons and Lua by Anonymous Coward · · Score: 0

      License -- Rebol's still proprietary, closed, with promises of occasionally permitting extensions some time in the future.. The MIT License is pretty close to "do what you will."

      Speed -- Look at the Debian project's great programming language shootout; for almost all tasks, Lua shoots big holes in Rebol for memory and cpu efficiency.

      Stable Target -- Rebol/Core is an endlessly shifting quicksand of changing options and partially functional library routines. Let's not even discuss the morass that is Rebol/View.

      In Production Now. Really In Production -- A lot of good commercial products use Lua. Only half-assed demonstrations from Carl Sassenrath's cult of Rebolistas use Rebol.

      Pragmatism -- Lua comes from some very humble roots, and has an extremely pragmatic design. In the past six years, Lua has not moved much as a language -- the last major cataclysmic chance was a few years back when 5.0 introduced true lexical scoping.

      In Short, Rebol has been promising not to suck Real Soon Now nearly as long as Duke Nukem Forever has been in development. Sure, the ubiquitous GUI is an eye catcher -- until you try to write a real app using it.

  67. Re:As usual, if you want lightweight and featurefu by nanosquid · · Score: 1

    No, but SIOD fits into 75K, has a track record with the Gimp and game extension, and has a use-it-any-way-you-want license. I've used it for web-related stuff and sysadminish things, too.

    Yes, and I remember SIOD fondly, but I think Lua is still a better choice. I slightly prefer SIOD's syntax to Lua's, but Lua's syntax is going to be far easier to pick up for programmers that have grown up on Java and C++. In terms of built-in data structures, I think Lua beats SIOD hands down, both in terms of usability and familiarity.

  68. It's REAL-TIME - don't underestimate that... by bytta · · Score: 1

    Over a 100 comments but noone has realized that it's a real-time scripting language.

    Many companies (including the one I work for) use Lua to extend compiled code on real-time industrial machines. Some even program everything in Lua.

  69. TomsRtBt uses it by iSrzMan · · Score: 1

    TomsRtBt adopted lua to smash down the code size of some of the linux utilities.

  70. Fine coffee and martial arts? by PHAEDRU5 · · Score: 2, Funny

    Hello? Anybody in there? Rio is known for Chicks! And tiny thongs! And Ipanema! And Copacabana! And Samba!

    Geeks. Geez.

    --
    668: Neighbour of the Beast
  71. Non-OO by CarpetShark · · Score: 1

    That ANSI-C compatibility will make it kind of annoying to implement any sort of OO interface to your app, though :/ My advice is to go with embedded python, unless you REALLY need an interpreter in 150k.

  72. Re:The ignorant and SlashDot authorship... by Anonymous Coward · · Score: 0

    not know by it's martial arts
    so what would you call capoeira? a carnival dance????
    IT IS a martial art!!

  73. Re:I'm sure I'm not the only one to point it out, by MyIS · · Score: 1

    There are a few replies to your post about merits of a base index of zero. But I wanted to elaborate on the collections framework thing.

    Lua, being a new language, should have right away very heavily discouraged the use of anything but abstracted opaque collection types such as unordered sets and collections and iterators. Sure, those seem a little clunky and slow compared to the iconic for(int i = 0; i < n; i++) but they actually allow for faster and more streamlined implementations when the traditional convention of a gap-less ordered array is dropped. And since embedded scripts (Lua's domain) are supposed to be very minimal, self-documenting "to-the-point" code, it would only help if the collections focus was more pervasive from day zero (heh).

    --
    http://zero-to-enterprise.blogspot.com/
  74. Football, samba, carnival? by jotaeleemeese · · Score: 1

    Honestly, I wonder in which caves some people live ....

    --
    IANAL but write like a drunk one.
  75. Fisrt airplane on the world by Netino · · Score: 0

    The first airplane was presented to the world in 1906, publicly, in Paris, by Alberto Santos Dumont, a Brazilian, so, before Wright brothers. The airplanes used until today, are based on a renewed model, named "Demoiselle", a brazilian airplane, presented to the world in 1907. Wright brothers presented their airplanes only in 1908 to the world, in Paris, and they have only a photo to proof it, "presumable" of 1903, to try "patent" the supposed invention. So who have/deserve the credits?

  76. So how do you pick a language? by SanityInAnarchy · · Score: 1

    I'm picking Python here because it's powerful, flexible, fast, and should have bindings to everything needed, even on Windows.

    Other than that, how do you pick a language? Do you just go for whatever was popular in school?

    --
    Don't thank God, thank a doctor!