Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Lua Tutorial (luatut.com)
56 points by signa11 on Nov 9, 2010 | hide | past | favorite | 25 comments


If this piques your interest, the best way to learn Lua is probably Ierusalimschy's _Programming in Lua, 2nd ed._ (http://www.inf.puc-rio.br/~roberto/pil2/). That starts from square one and gets to advanced Lua programming, the C API, etc. in just over 300 pages.

The first edition is free online (http://www.lua.org/pil/); the language changed somewhat between the two, but it gives a reasonable impression.

There's also a lot of content at http://lua-users.org/, including the wiki and mailing list archives.

LuaRocks (http://luarocks.org/) is a central library collection (such as CPAN, ruby gems, etc.), though not everybody uses it. For people on Windows, "Lua for Windows" (http://code.google.com/p/luaforwindows/) is a pretty good batteries-included distribution.


Very nice.

It kinda feels like it ends before it gets past the stuff I could guess from knowing my way around other scripting languages, but I'm guessing it's a work-in-progress. It'd probably benefit from even a brief "Why Lua?" discussion, though.

It's very pretty, but I'd consider getting rid of the text-shadow on code examples.

(Minor point, but: # as a length operator isn't entirely unique to Lua, Perl has $#foo to return the length [kinda] of the array @foo).


In Perl $#foo returns the index of the last element. To get the length you use @foo in scalar context. For eg:

    my @bag_of_stuff = qw(do re me fa so la si);

    say $#bag_of_stuff;        # => 6

    say scalar @bag_of_stuff;  # => 7
NB. Lua arrays start at 1. Perl & most other languages start with 0 (zero) index


Yeah, I know (hence "kinda"), didn't seem like the time or place to go on about Perl's quirks, though ;)


There was a screencast on "Why Lua" posted to HN not too long ago.



Thank you! That's it. He makes a compelling case :)


text-shadow should be removed from the body text as well, it makes the text look blurry and harder to read.


The length operator(#) is a bit misleading when used with tables, you can only rely on it with array like tables with numeric indexes without holes in them (no nil values). Thats a big gotcha one should mention.


yeah that is true. most of the time array would not have holes. when it does, using 'table.maxn(...)' works.


  Contrary to what hardcore "coders" tell you, notepad is 
  not your ideal development environment.
I don't want to bring up this debate again, but I do want to point out that this is a strawman. No one codes in Notepad or TextEdit. So for me, the tutorial starts off on a rotten note.


Indeed. (I use Emacs for Lua, which seems to work fine. vi would be sufficient.)

Also, Lua is byte-compiled, rather than a pure interpreter. (The compiler is automatic and quite fast, though, so it's easy to miss.)


As I see it Lua only make sense for:

* Video Games / Graphics engine scripting

* MySQL administration

* Maybe also if you want to add embeddable scripting to your app, but then why not go with more popular choice, like Python?

Choosing tables as a main datatype rather than associative arrays is a best choice in Lua design!


> * Maybe also if you want to add embeddable scripting to your app, but then why not go with more popular choice, like Python?

The Lua VM is extremely lean, and it has been designed from scratch for embeddability in C and C++ programs (it is written in the common subset of C89 and C++).

Furthermore, if your code runs on x86 or x64, you can switch to LuaJIT which is amazingly fast. LuaJIT has the same perfirmance profile as Java (but it is mre frugal on memory). The Lua interpreter is about as fast as Pypy, the fastest Python JIT compiler.

See http://shootout.alioth.debian.org/u32/code-used-time-used-sh... for the details.


Well, Python and its ilk are getting pretty huge. And most of its programmers are pretty used to the (massive) standard library. So if you just include the interpreter, Python programmers will be a bit confused. With Lua, that's not an issue.

Also, it is a very clean and simple language. It's basically Javascript done right.

If I remember correctly, it's one of Zed Shaw's current obsessions. So I bet we're going to see some interesting combination of Lua with his new Mongrel2 project. That combined with the growing library and the packaging mechanism (rocks) might further improve the publicity of Lua for stand-alone scripting.


Good idea: everybody loves Lua.

But why oh why is the whole page built from tiny little Flash things? It looks ridiculous if Click2Flash (or similar) is installed. Unusable.


> But why oh why is the whole page built from tiny little Flash things? It looks ridiculous if Click2Flash (or similar) is installed. Unusable.

Custom fonts, HTML4-way.


I have Opera/Linux without Flash plugin, and I could read everything just fine. Strange.


It tries to use Flash for fonts and falls back to standard html if you are missing the Flash plugin. If you use something that blocks Flash then you just see boxes everywhere there is supposed to be a text heading.


Am using FF4.0b6 with FlashBlock 1.5.14.2 and it correctly fell back to standard html.


I guess this is a Chrome problem, then.


It's worth keeping in mind that if you care about Unicode, Lua doesn't really support it. See http://lua-users.org/wiki/LuaUnicode for the details.


That's an interesting point, because of all the languages I prefer working with Unicode (UTF-8) in Lua.

This is because I know exactly where I am, there's no under-the-hood encoding/decoding to slow down my application, etc. This is a common problem I find in e.g. Python applications. If I need character count instead of byte count, I pull in a unicode library. For most things this is not necessary and unicode strings are just passed through transparently.

Finally there are numerous modules and ways to interpret and manipulate unicode strings in Lua, should you actually need that.


Cannot scroll properly on safari, Mac OS X; When scrolling, it stops whenever it hits a flash thing. Also excersize > exercize. Looks cute. You might want to mention metatables in the crash course.


Why are all the headings in flash? Why?!




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: