

Lua Tutorial - signa11
http://luatut.com/

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

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

~~~
draegtun
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_

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

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

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

------
nivertech
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!

~~~
pygy_
> * 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...](http://shootout.alioth.debian.org/u32/code-used-time-used-shapes.php)
for the details.

------
djacobs

      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.

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

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

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

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

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

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

~~~
naner
I guess this is a Chrome problem, then.

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

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

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

~~~
hartror
Why are all the headings in flash? Why?!

