3 ms·
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.
by silentbicycle 16y ago
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/ 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 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/ 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).
- silentbicycle 16y agoAlso, besides LuaRocks, some more libraries are listed on the Lua wiki: http://lua-users.org/wiki/LibrariesAndBindings http://lua-users.org/wiki/LibrariesAndBindings
- pygy_ 16y agoNitpick: 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 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.
- silentbicycle 16y ago5.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.
- pygy_ 16y agoI 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/ http://markaby.rubyforge.org/ , just in case ;-)
- silentbicycle 16y agoHah. 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.
- pygy_ 16y agoUsing _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?