LuaJIT 2.0.5 and 2.1.0-beta3 released
luajit.org
luajit.org
Anyway, it's a stack I'm really happy to be using. Asynchronous IO without any code nesting. I wrote more about the benefits here: http://leafo.net/posts/itchio-and-coroutines.html
[3] https://itch.io/
I also made web server infrastructure for the Lua package manager LuaRocks in the same stack: https://luarocks.org Source is on github: https://github.com/luarocks/luarocks-site
Lua (especially with LuaJIT) is a great choice for web development.
Question, since Lapis just transcode Moonscript into Lua to be used with OpenResty - why is Lapis so much slower than raw OpenResty/Lua?
What's "inherent" in moonscript that makes it slower?
In case you're not aware Lapis = Moonscript + OpenResty.
And Moonsript is like Coffeescript but for Lua
You can use Moonscript, but you can also use pure Lua.
It has nothing to do with MoonScript. MoonScript generates speedy code.
Kong[2] uses it extensively, by leveraging the underlying OpenResty[3] framework.
[1] http://luajit.org/ext_ffi.html
Fully agree about the awesomeness of LuaJIT and incredible capabilities of Mike Pall, but also the reason I've stopped considering using LuaJIT for projects that should be "future proof". I think that depending on technology which can only be maintained by one genius is too much of a risk.
Compare this with PUC Lua [2], which seems to have very few bugs: only 4 in 5.3.3 and 3 in 5.3.2.
LuaJIT and PUC Lua appear to be very similar superficially ("LuaJIT is Lua, but fast"). The relative bug counts reinforce the fact that in the details, the two implementations are very different - for example, LuaJIT uses a lot of assembly language while PUC Lua is pure C89.
The advantages of LuaJIT over PUC Lua seem to be performance and its FFI. I thought PUC Lua's only advantage was portability, but perhaps PUC Lua is also a generally more "correct" implementation?
I have also seen non-jit-related bugs impact us in production.
BUT, LuaJIT really is FASTER. Even when JIT cannot be used (e.g. on iOS), it can still be several times faster than PUC Lua.
And that speed is a real killer feature for us. Otherwise, we'd just use JavaScript.
While LuaJIT can't be JITed either on iOS, I think the general consensus is that non-jit Lua is faster than non-jit JS.
I do a lot of bridging Lua to native, and that's another area where Lua is often considered more efficient.
Again, these thoughts may be out of date.
Also, LuaJIT has other extensions aside from FFI; see the website.
We used to run Lua on a 300MHz MIPS processor and it was impressive in how well it worked on that constrained platform(only 8mb is system ram, of that Lua ran in a fixed 400kb block).
[/plug]
The manual and API docs are hand written in markdown.
New release will be out in a few days.
Regardless, I'm enjoying Lua more and more and it's becoming my go-to language for prototyping and exploring concepts. The code just flows more naturally than in other languages.
Like, Lua is bring-your-own battery, true. For everything else, there's Penlight/luarocks, though.
There's a very nice "package manager" for downloading and installing modules, called LuaRocks. On the other hand, lack of tooling is a big issue. ZeroBrane seems to be only decent IDE with debugging support.
There's ton of stuff in libraries and Lua extensions, you just have to be careful about what you are integrating. You might for example end up with two incompatible implementations of class system from two different libs.
function alive?
... blah
end
Is so much more natural, after being exposed to ruby. But maintaining forks is hard, so I've slowly gotten use to the standard.It's a shame that the development is so conservative, and closed, but despite that it is a great language to play with.
A function that tests for something involving its arguments
is called a predicate and usually ends in p or -p.
http://www.cliki.net/Naming+conventionsIncoherent? 10 years of Lua development, never had a problem with it. In fact, the ability to use a table as either an array or a dictionary is one of the great features of the language. Most newbie Lua coders get over the differences pretty fast. For everyone else, there is lua-enumerable.lua ...
I love Lua. It's embeddable, it's written with newbie-friendliness in mind... but I still think it has flaws that I wish we'd see fixed. To me, the biggest one missing is just some simple convenience stuff for higher-order-functions - like I said before, the lack of a ternary "inline if" which is super-handy for writing one-line lambdas, and the verbosity of its lambda syntax.
3DS port: https://github.com/rweichler/luajit-3DS
iOS runtime inspector: https://github.com/rweichler/lucy
Cydia alternative: https://github.com/rweichler/jjjj
And this is just stuff by me, some schlep. LuaJIT is so underrated it's kind of sad.
Edit: By the way, can someone explain why ipairs() is implemented, but not pairs()?
I'm guessing that pairs() is not JIT-compiled because iterating over a hash table involves logic that is significantly more complicated than iterating over an array (like ipairs()).
https://www.freelists.org/post/luajit/LuaJIT-21-status-and-s...
It is one of very few packages broken this way, along with basically only XFree86 4.8.0
:-(
Getting LuaJIT to work on 64-bit OS X required building a custom emacs with linker flags -pagezero_size 10000 -image_base 100000000. This is unfortunate since obviously users will not take the time to build an emacs with custom linker flags. But more generally, this is an issue any time you want to embed LuaJIT in an application plugin rather than the application itself.
There's a bunch of scattered info about the issue:
https://gist.github.com/nddrylliog/8722197
http://hacksoflife.blogspot.fr/2012/12/integrating-luajit-wi...
https://en.blog.nic.cz/2015/08/12/embedding-luajit-in-30-min...
http://luajit.org/install.html
I was hoping there might be a way of sidestepping the issue somehow. If anyone has any ideas, it would be appreciated. LuaJIT has some nice speed improvements compared to standard Lua, but more importantly it has a pretty amazing FFI library. The C declaration parser in particular is valuable.
(Yes, I know it's pointless to hook LuaJIT to emacs. It's mostly a "just because" project.)
Why use LuaJIT over plain Lua here? I can't imagine that you need the extra speed in a text editor. The ffi is available for normal lua too: https://github.com/facebook/luaffifb/
So here's something to pop up a message box on Windows:
local ffi = require("ffi")
ffi.cdef[[
int MessageBoxA(void *w, const char *txt, const char *cap, int type);
]]
ffi.C.MessageBoxA(nil, "Hello world!", "Test", 0)
Bing! Again, that was far too easy, no?Compare this with the effort required to bind that function using the classic Lua/C API: create an extra C file, add a C function that retrieves and checks the argument types passed from Lua and calls the actual C function, add a list of module functions and their names, add a luaopen_* function and register all module functions, compile and link it into a shared library (DLL), move it to the proper path, add Lua code that loads the module aaaand ... finally call the binding function. Phew!
I think the main argument against Lua + luaffifb is that it might require an external dependency: luarocks. Whereas if someone were to theoretically provide Lua integration with emacs, it might be a good idea to offer the ffi library as a baseline feature.
This is a weak argument, because it should be possible to embed luaffifb plus Lua inside of a linked library, with no need to depend on luarocks.
It's probably best to explore both options.
On the down side, TCC doesn't support all the architectures I use, so I mostly use it for proof-of-concept and throw away code.
One thing I keep thinking is to possibly use TCC (or parts of it) to parse C header files directly, so it would be easier to use an FFI in Lua.
[1] https://github.com/spc476/lua-conmanorg/blob/master/src/tcc....
[2] https://github.com/spc476/lua-conmanorg/blob/master/lua/cc.l...
[3] https://github.com/spc476/LPeg-Parsers/blob/json-1.0.0/json....
My mouth was hanging open when I discovered that you could literally a verbatim header with packed structs and use it and it would work. Then I looked at the source to find out what they were using as a compiler frontend; it's all hand written. Incredible.