I left Python for Lua years ago, haven't looked back. Even if you don't care about tail-call optimization, etc., LuaJIT (http://shootout.alioth.debian.org/u32/benchmark.php?test=all...) is pretty compelling. (Also, OCaml, though I use Lua more day-to-day.)
Love lua. Luajit is stupid fast and the ffi stuff makes it a snap to integrate with other libraries. You can find Lua in neat places like nginx, redis, tokyotyrant...
I dislike the direction python has been going (twisted...i mean asyncio, type annotations, f strings). Lua is like a breath of fresh air.
Downsides are small standard library and 1-based indexing shudder.
LuaJIT (http://luajit.org/) performs quite well. While I can't say it'd be impossible, optimizing Python similarly would be much harder - Lua's tiny implementation and tendency to do everything in terms of a small and orthogonal group of concepts means it has far less that needs to be optimized. Python is pretty hairy in comparison.
Lua seems to have a similar advantage over Javascript, as well. LuaJIT beats Javascript V8 by a wide margin (http://shootout.alioth.debian.org/u64/benchmark.php?test=all...). It's not like Javascript implementers lack resources, either. LuaJIT is the work of one person.
LuaJIT is really impressive, but honestly, the stock interpreter is fast enough for me in general, and I'm fine with just moving hotspots to C as needed.
I'm more impressed with how concise Lua is. I've got the Lua 5.1 Reference Manual sitting in front of me. It's 103 pages for the whole language (roughly half of which is the C API), the entire syntax fits on page 95, etc. I can keep it all in my mental L1 cache, so to speak. Yet, it's expressive enough to have displaced Python as my go-to language. It's not perfect, but I'm very happy with the trade-offs it makes.
I'll be psyched once it's ported to a couple more hardware platforms, though.
Lua's other strong point here is that it has an especially nice C API. Unlike Perl, Python, and Ruby, it was written primarily to script C, with use as a standalone language being secondary.
I prefer Lua to all of those, but that again is a matter of taste.
And yes, Lua is pretty fast, and LuaJIT (http://luajit.org/) is so fast that it's a major outlier among scripting languages.
Lua is pretty close, and pretty close to Python in terms of style and strengths.
Edit: I actually forgot about the split between LuaJIT (which hasn’t changed since Lua 5.1), and the PUC Lua implementation, which has continued to evolve. I was thinking of the LuaJIT version.
When the fundamental design of the language is stacked against your style of working, the cognitive dissonance of using so many workarounds is a serious problem.
I just switched to Lua during the Python 2 to 3 transition, and I haven't looked back. Real closures and tail calls, no GIL, a vastly more tasteful design, a dead-simple C API, and the whole shebang is a tenth the size of Python.
I wanted to have just faster dynamic lang. Common lisp is there, but the performant implementations are heavy. CFFI is well developed, and systems like Lispworks allow you to create a dll with "C" entry point (but it's commercial and costs some money)
javascript's v8 was my next choice, but then found about luajit and using it since. The jit and the ffi are very good selling points. Also the small size of the project, and very fast recompile time (unlike say pypy)
I've used lua back in 2001, 2002 as a testing facility for a library I did at work.
It's worth noting, I'm mostly not defending Lua here. I enjoyed my time with it, and then when I put it down I realized how unhappy I was with it.
There's no language I really truly love, but the one I find myself recommending as a result of good tradeoffs between simplicity and usability is Python.
Lua is much faster than Ruby/Python/Perl/&c. It still doesn't get close even to the higher-level compiled languages like Common Lisp and Haskell, but e.g. the programming language shootout [1] makes it pretty clear that Lua is still a league above the other dynamic languages. For just a quick result, I tried timing just the Hello World program in Python, Ruby, and Lua, and while startup time isn't going to be the bottleneck of the world of modern web development, it's still a telling result:
$ time python2.7 -c "print 'Hello, world'"
real 0m0.107s
user 0m0.080s
sys 0m0.023s
$ time ruby -e "puts 'Hello, world'"
Hello, world
real 0m0.338s
user 0m0.030s
sys 0m0.013s
$ time lua -e "print('Hello, world')"
Hello, world
real 0m0.008s
user 0m0.000s
sys 0m0.003s
That said, I kneejerk-ly agree with you about Lua being an awkward medium for expressing programs. I personally haven't ever gotten to the status where Lua was as natural as Python, but I have also used Python a great deal more, so I don't know if my attitude is attributable to Lua's design, or Python's plenitude of libraries, or merely the experience differential between the two.
With the common complaints about the various dynamic languages of choice being slow, I don't understand why Lua hasn't gotten more attention. The standard interpreter is many times faster than Ruby and Python, and LuaJIT is several times faster still. It's also an elegant language with a tiny core. I wish it had implicit returns, but nothing's perfect.
I just looked at the Alioth benchmarks and found that Lua (not JIT) is around three times faster than Python 3. I remember the differences being larger with Python 2.x, but I'm not going to take the time to look for those benchmarks. On one benchmark, Lua was much slower.
I barely know Python, though I've found it fairly easy to pick up and use when I've needed to. I know Ruby pretty well though, and I find Lua about as easy to use as Ruby.
Lua is elegant, small and fast, especially when you're using LuaJIT. It's the language I reach for first when I need to embed a scripting language in a system (perhaps to replace configuration files).
Its only real drawback is a lack of libraries/package manager compared to, say, Python/Ruby (respectively). I guess some people might miss built-in support for classes.
I have noticed a significant speedup using LuaJit, similar to PyPy compared to normal Python. I'm guessing if LuaJit & PyPy were used, the performance for Lua & Python would be similar to JS in these results.
reply