Why has Lua adoption been so slow outside the game world?
Why has Lua adoption been so slow outside the game world?
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).
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.
And yes, the 5.2 environment handling sounds like an improvement to me as well.
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 ;-)
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.
* 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?
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.
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.
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.
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
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).
No libraries.
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.