Hacker News new | comments | show | ask | jobs | submit login

I'm frustrated by Lua, because it seems such a productive, pragmatic language that is performant to boot (let alone the numbers LuaJIT is posting), but yet it never seems to gain momentum.

Why has Lua adoption been so slow outside the game world?




Lua is gaining momentum, but it's been a very slow burner. There are a lot of programs (mostly games) that use it, and they aren't required to be open about it. Lua also improved quite a bit (IMHO) between 4.0 and 5.1, but 5.1 has only been out since 2006.

Some things omitted from Lua's std libs because you'd typically just do them in C anyway, and it keeps Lua very small. While you don't need to know C to use Lua (and there are community libraries for them, see LuaRocks: http://luarocks.org/repositories/rocks/), it really shines in symbiosis with C.

Most web devs don't know C, though, so it misses quite a bit of the free hype that would come from word of mouth in that community (look at e.g. Ruby), especially compared to word of mouth in the (NDA-infested) gaming industry.

FWIW, I don't think it would take long for somebody proficient in Javascript (or Python) to learn Lua - This comment (http://news.ycombinator.com/item?id=1786280) is a good summary. The languages are very similar in overall design (prototypes, JSON/dict-style objects, etc.), but where Javascript has numerous design bugs frozen in its spec (thanks to the browser wars) and "The Good Parts" telling how to sidestepping them, Lua had 15 extra years to evolve and fixed them.

Recommended intro: Ieursalimschy's _Programming in Lua, 2nd ed._ (http://www.inf.puc-rio.br/~roberto/pil2/). The first edition is free online, but covers 4.0, and the language changed a lot (most notably, the packaging system).


Nitpick: The first edition of the PiL Book covers Lua 5.0 which is very similar to 5.1.

The most noticeable changes are the vararg handling, the module system (as you said, but it will be phased out in v5.2), and some library changes.

The differences are listed here: http://www.lua.org/manual/5.1/manual.html#7

That said, I purchased the second edition to understand the module system, only to decide not to use it anyway :-). I don't like the way the `module` function pollutes the global namespace.


5.0, not 4.0 - you're right, thanks. Missed the edit window. :/

And yes, the 5.2 environment handling sounds like an improvement to me as well.


I liked setfenv() for its versatility.

I implemented a toy markaby [1] clone in Lua using it.

    tpl = html(function()
        head(function() --> tag names should be non-locals. They will be rebound at runtime.
            title "Barbazor"
            link {rel = "stylesheet", type = "text/css", href = "style.css"}
        end
        body(function()
            h1 {"Big title"; id = "title"}
            div {class = "foo"; function()
                for i=1,5 do
                    p( "counting: " .. i )
                end
            end}
        end
    end
    
    render( tpl ) --> returns clean, well indented HTML.
I don't think it can be done with the new environment system without reimplementing setfenv. You could achieve the same effect by passing an explicit param to anonymous functions, but it would look worse IMO.

This example also highlights a weakness in the language syntax: lambdas are ugly. Functions are first-class, semantically, but not syntactically, which is sad.

[1] http://markaby.rubyforge.org/ , just in case ;-)


Hah. I did exactly the same thing. I usually use discount instead, though. To my understanding, it'd work to set _ENV's metatable's __index to a table w/ HTML tag generators. I've read about _ENV but haven't actually used 5.2-work4 yet. (I started using 5.2-work2 but they went and changed it again, so now I'm waiting until it's a sure thing.)

I agree that the syntax for first class funs could be more concise, but that's true of any language that requires a "return" keyword (i.e., is statement-based rather than expression-based). I think "fun x -> x + 1 end" would be better, but maybe that's just the OCaml talking.


Using _ENV would not be that simple.

    * The library and template files may have different _ENVs. 
    * The _ENV of the tempalte file could already have an __index.
You'd have to add something like `_ENV = luhtml.makeENV(_ENV)` before your template definitions to take care of this.

The only way to have a clean template file would be to emulate setfenv using the debug library.

--

My main gripe with the current syntax is that, when scanning the code, function declarations and invocations are too similar.

I'd like to have somthing like

    :[x] print(x); -> x+1 end 
or

    :]x[ -> x+1 ]
Both are unambiguous, and would allow to pass a lambda to a function requiring a single argument without parenthesis, like you can already with strings and table litterals.

    somefun :]x[ dosomething( x ) ]
I prefer the second syntax because of the initial happy smiley, although it the reversed brackets are alien and would cause an uproar if they were to be added in any popular language.

--

At last, what is discount?


Discount (http://www.pell.portland.or.us/~orc/Code/discount/) is a very fast, C-based implementation of Markdown (http://daringfireball.net/projects/markdown/).

I have a Lua wrapper for it, but just noticed that I don't have it on my github page. I'll post it soonish. Somebody else has a Lua wrapper for an older version of discount, but includes the discount source in it (!), and it's been updated due to security-related bugs, so that's out.

Talking about reversed brackets, look at J (http://www.jsoftware.com/). The only language I've seen that uses ], [, {, and } as unpaired operators. Pretty serious heresy. Cool language, though.


Thanks for all that :)


Also, besides LuaRocks, some more libraries are listed on the Lua wiki: http://lua-users.org/wiki/LibrariesAndBindings


I think this mostly has to do with the 'Batteries -not- included' approach of Lua.

This is mainly done to keep the language/vm compact and embeddable, yet what it leads to is many similar implementations of modules that do not play well together.


I read a related article a while back: http://journal.dedasys.com/2010/03/30/where-tcl-and-tk-went-... It's interesting to draw parallels to Lua, they both started out as embedded scripting languages with a small core.


Great article:-) I think managing the addition of batteries is definitely tricky for a language like Lua. Some of its users do not want any additional baggage: they want small, fast and easy to embed. Other people may want to use it as a 'scripting language', and thus want to have a bunch of libraries and additional goodies to get stuff done with.


This. Lua doesn't even have a standard class/inheritance model. If you want that, you implement it in-language. There are some nice general purpose ones out there, but nothing canonical.

If someone makes a killer web framework on top of one of these models, that might establish the standard and bootstrap the Lua scene, kind of like how Rails established a lot of idioms for Ruby.


re: makes a killer web framework

There have been two Ruby web framework ported to Lua:

* Orbit (http://orbit.luaforge.net/) - Camping port

* Mercury (http://github.com/nrk/mercury) - Sinatra port


There's also Kepler (http://www.keplerproject.org/), which I haven't used, and WSAPI (http://keplerproject.github.com/wsapi/), which is roughly like Rack or WSGI. It's not a "web framework", but using WSAPI with FastCGI works well for CGI-ish stuff.


I think those who find it a productive tool, just use it without waiting for the whole herd to head that direction - and since it's just a tool that provides a productivity edge - why advertise too much about it on blogs ;-)

http://www.cisco.com/en/US/docs/security/csd/csd35/configura...

(disclaimer: cisco is my employer).

(disclaimer#2: I did use lua for quick prototypes that involved the low-level C code and higher level logic to glue it. So the positive feelings I got from it may be biasing me).


Agreed. This is the first time I've seen someone mention lua on a non-lua based community site. :(


There have been quite a few sightings of Lua here on HN: http://www.google.com/search?q=site:news.ycombinator.com+lua


Why has Lua adoption been so slow outside the game world?

No libraries.


Well, there are plenty at LuaRocks (http://luarocks.org/repositories/rocks/). It's no CPAN, but the essentials are there. I'm working on a couple, such as Tamale (http://github.com/silentbicycle/tamale/), which adds Erlang-style pattern matching. I'll post it on LuaRocks once the docs are done.

Of course, if you're embedding Lua (in a game, for example) you've already got the libraries you need, and extra libraries would just get in the way.




Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | DMCA | Apply to YC | Contact

Search: