

Why isn't everyone using Lua? - martijn_himself

I came across the Lua programming language and started reading the first edition of 'Programming in Lua', which is available for free online (http://www.lua.org/pil).<p>I am incredibly impressed by the conciseness of the language and its syntax and really like it (there are only a handful of types, the 'table' data structure can be used to easily create any complex data structure), it is fast and is designed to be called as a script from c, and c functions can be easily called from it. Intuitively it appeals to me even more than Python does.<p>Its adoption seems to suggest it is not widely used outside game programming? Why? What is wrong with you people? ;)
======
cmorrisrsg
The Lua community has been historically more focused on embedded and scripting
scenarios, and less on building a comprehensive platform for libraries and
applications (compare the quality and availability of LuaRocks to PyPI, Ruby
Gems, CPAN, etc.). That combined with the almost non-existent standard library
means that not only does Lua not give you a solid base of code to build off
of, it's hard to find a community-driven one as well. This leads to developers
having to play mix-and-match to get a good base running. Also, the "table can
be used to emulate any structure" piece means that every library and developer
does OO and modules just a little bit differently, harming reuse across code
bases.

There are a couple of syntax decisions (default globals, no ++ or --, indexes
start at 1) that might cause negative reactions, but I'd put the lack of
libraries and frameworks above that.

Lua is still awesome for simplicity, easy C binding, and performance, but
deciding to build a new project in Lua requires a significant investment in
just getting the base libraries put together.

------
jordandanford
I've always gotten the impression that Lua has a somewhat anemic standard
library and a somewhat limited set of abstractions, in contrast to the things
that draw me to Python – is this still accurate? Python, Ruby, etc. have a
wide range of built-in functionality, which allows them to stand on their own,
whereas Lua seems to be intended for use with C programs and libraries,
keeping it in the game/scripting world. Are these assumptions still accurate?
(Also, indexing from one is just frustrating when almost everything else is
zero-based!)

~~~
martijn_himself
That seems definitely accurate. From my limited experience it certainly seems
Lua has the more minimalistic approach, although that must have been a
conscious decision on the part of the authors. I like how built-in functions
can be 'overriden' (more like replaced) to be made more restrictive to create
a sandboxed environment. I agree I can't think of any good reason for the one-
based indexing, it seems to be a bit of a gimmick :)

------
madhouse
Personally, I find the syntax horrible. A good few years ago, I wrote
reasonably complex stuff in Lua (a game addon, you wouldn't have guessed,
right? :P), and it was quite painful to do that.

It doesn't help that it's embedded into larger applications most of the time,
which do not allow easy debugging, if at all.

~~~
martijn_himself
That's really interesting. Obviously, I've only started reading the docs and
have no real-world experience with the language. I hadn't even thought about
debugging. Do you know an alternative language that you would prefer to use in
that context? Do you think the reason for its popularity in game programming
is because there is not really any alternative?

------
andrewcooke
i don't see any great advantage that outweighs the cost of switching from
python. the language is not that different, but i already know python, my co-
workers know python, and python has more libraries and wider support.

i am not criticising lua in any way - from what i know of it, it is exemplary
(there's a good paper on its implementation that i enjoyed). but languages
don't succeed on intrinsic qualities alone.

~~~
martijn_himself
I don't have a lot of experience with Python, is it as easy to call out from
and into c code as with Lua? (I am now just guessing as to why a game
programmer would choose Lua over Python).

~~~
andrewcooke
lua is easier to embed, is smaller, and has better performance. it's also a
slightly cleaner language (all other things being equal, i think it is
slightly better than python: the handling of tables is more regular; it has
better support for continuations; it has tco; and correct scoping). on the
downside, the "maps as arrays" approach is a bit clumsy.

~~~
cheald
Lua tables are sort of two-headed beasts. They aren't like PHP's array
construct, which is effectively always an ordered dict. In Lua, an ordered
list and a dictionary are both expressed by the same type, but are effectively
different types. You can even have both an ordered list, and a dictionary in
the same table.

    
    
       foo = {1,2,3}
    

This is an ordered list. #foo -> 3

    
    
       foo = {foo = "bar", baz = "bin"}
    

This is a dictionary. #foo -> 0; the reason for this is that #foo (or more
clearly, the length of foo) measures the length of the ordered list portion of
a table. If you iterate an ordered list with ipairs(), you will only get the
ordered list entries, even if you were to have dictionary data in the same
table.

This is somewhat unintuitive in the context of other similar languages, but
once you have a grasp of it, it makes a lot of sense, and is remarkably
elegant.

------
cheald
Lua is a wonderful language. Small, terse, extremely powerful, easily
embedded, and fast. I'm a huge fan of it.

It does suffer from the lack of a robust standard library, because it is
intended to be embedded, where it should inherit the majority of its
functionality from the host application. That said, when embedded in a rich
host environment, it's a marvelous tool.

------
neworbit
There's a pretty slick Redis implementation at
<http://antirez.com/post/scripting-branch-released.html> \- I've been meaning
to check it out for some real world usage. Mostly I've seen it in Warcrack.

------
jolan
It's not just for games. One of the best Jabber/XMPP servers is written in
Lua:

<http://prosody.im/>

------
inportb
I just disagree with the 1-based indexing...

