5 ms·
I don't know Lua, but this is the first time I've heard Lua and Ruby equated in terms of expressibility/flexibility (i.e. "high-level"?). Is that a particularl
by nod 18y ago
I don't know Lua, but this is the first time I've heard Lua and Ruby equated in terms of expressibility/flexibility (i.e. "high-level"?). Is that a particularly relevant comparison?
- fizx 18y agoMe too. It motivated me to spend the last 15 minutes looking into Lua. Similarities: Block/lambda support and syntax, optional parentheses, control statements as block, prefix, or postfix. OTOH, "how come Lua is not as widespread as say, Python ? I'd say the answer is this: there is no real standard library, and as opposed to Python, Lua doesn't come with batteries included." -- http://www.ivy.fr/blog/index.php/2008/03/17/83-kahlua-lua-on-the-jvm http://www.ivy.fr/blog/index.php/2008/03/17/83-kahlua-lua-on...
- brianm 18y agoVery true, Lua is optimized for being very small, fast, and portable. It optimizes for embedding, which means you cannot make assumptions about what you are allowed to do, so it errs on the side of very little. On the other hand, interfacing to C is the nicest of anything I have done, by a long shot, so the lack of batteries isn't that painful in practice. It fills a different niche than python or ruby, in its, it shines.
- nihilocrat 18y agoLua presumes you've already got your own batteries, thank you, and you don't want those crummy off-brand ones that always seem to come "included". Thus, I feel a Lua - to - Ruby/Python comparison is sort of erroneous. Use Lua when you already have all your tools. Use Ruby/Python when you don't have any tools, and you want cool whizbang higher-level stuff. Honestly the benchmark is wholly unsurprising to me; Lua is a much more minimal language. If you need another language to lump Lua with, lump it with Javascript sooner than you would Ruby or Python.
- nuclear_eclipse 18y agoHowever, as a longtime user of Lua, I would still greatly appreciate a default set of "batteries-included" libraries as an option, like what you'll find in Python, so that it could/would be that much faster to write simple applications in pure Lua, without needing to deal with compiling/bridging to C/C++ libraries...
- silentbicycle 18y agoAs a longtime Lua user, you're probably aware of this, but I'm also writing for the other people reading the thread... :) Look at LuaRocks (http://www.luarocks.org/ http://www.luarocks.org/). It's an attempt at a CPAN-like package collection. The stdlib and bitlib libraries, in particular, are pretty necessary. (Also, http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/ http://www.tecgraf.puc-rio.br/~lhf/ftp/lua/ has some others.) Lua errs on the side of only putting what can be implemented fully portably in ANSI C in its standard libary, which makes it a bit spare.
- palish 18y agoYeah, actually. Lua isn't as clean as Ruby (or Python, or your_favorite_language), but it has the advanced features you'd expect from a powerful scripting language: closures, coroutines, etc. Rather, Lua is like a really experienced prostitute. Not necessarily beautiful, but can do all the tricks and can get the job done efficiently and inexpensively. To get started with Lua, I'd recommend PIL: http://www.lua.org/pil/ http://www.lua.org/pil/
- LogicHoleFlaw 18y agoAre you serious? Lua has an extremely clean and orthogonal core. It's got serious CS mojo. The "batteries not included" bit is probably the greatest detraction to Lua as a general-purpose scripting language.
- palish 18y agoCertainly. I didn't mean to deride anyone's work with the comparison. I meant, some of the implementation decisions seem arbitrary, and seem like they were made "for the sake of being different". For example, Lua's use of two dashes for line comments, and --[[ and --]] for block quotes. That lets you remove the first --[[ in a block quote without causing the program to break, because the "closing" block quote is commented out at that point (because --]] is a comment at that point). But really, that's so different from other languages that it seems like a liability rather than an asset. That's what I meant by "not necessarily beautiful". It is definitely beautiful in certain other aspects, though. Also, if I were writing a scripting language, I'd love for it to be "like a prostitute". Even if nobody respected it, everyone would be using it.
- Xichekolas 18y ago> Even if nobody respected it, everyone would be using it. By that metric, PHP is the scripting language for you. ;) The double hyphen comment is used elsewhere. SQL comes to mind.
- davidw 18y agoIn that vein, don't array indexes start with 1, instead of 0? Erlang does that too, and it's a bit weird, but not a show stopper.
- brianm 18y agoHaving done a lot of both, Lua feels more pythonic than rubyish in many small ways. Objects are just syntactic sugar where self is the first arg (though unlike python, lua has the syntactic sugar to make it prettier to look at), etc. Interestingly, typical OO Lua is prototype based, not class based -- in that way it is more javascriptish. Most lua codebases I have seen tend to be written in what I call an "imperative functional" style, where the language isn't purely functional, but functions are the most common means of abstraction. It has proper anonymous functions, lexical scoping, etc so you can write very rubyish code (such as moonunit http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lua/test/moonunit.lua http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lu... and using it http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lua/test/test.lua http://svn.apache.org/repos/asf/httpd/httpd/trunk/modules/lu... ).
- Xichekolas 18y agoA unit testing framework in 37 lines of code, not too shabby.
- brianm 18y agowith color coded output ;-)
- silentbicycle 18y agoYes. In short, Lua's philosophy is to keep the core language as small as possible, but to include features that make it easy to add major language features as necessary. Adding an object system to the language is trivial, for example. (It doesn't have hygienic macros, though there are some side projects that attempt to add them. No experience with them, though...I'd just use Scheme.) Lua feels to me like a minimalistic, more internally consistent Python.