5 ms·
Could anyone explain, why Lua is so special?
by wildchild 14y ago
Could anyone explain, why Lua is so special?
- AlexanderDhoore 14y agoIt's very small and uses very little memory. It's designed to be embedded. And has a liberal license (MIT).
- deweerdt 14y agoIt's not the language itself. It's its implementation. Embedding a Lua interpreter in a C program is straightforward. See the 'Python' and 'Java' slides in the OP: it's all about integration.
- Slackwise 14y agoTake JavaScript, remove all the wonky stuff, and now you've got Lua. Then ask yourself, why has JavaScript become popular outside the browser?
- ams6110 14y agoJavascript is popular outside the browser not because it's a great programming language, but because it gets us back to where we were before the browser became the dominant app delivery platform: it's now again possible to write your entire client-server app in one language.
- Slackwise 14y agoIf you're talking Node.js, sure, but that was a stepping stone. It's now being used for all sorts of weird things, like WinRT, and as GNOME's flagship desktop app language. These need not have any server-side components. A large part is obviously that JavaScript is now well known and many developers have been exposed to it, but also because a minimal prototype language with first class functions is often all you need or want, just like Lua. (I assume this has been realized after exposure to JavaScript, or maybe I'm giving JS devs too much credit and they're not fans of minimal and clean languages.)
- xradionut 14y agoJavaScript is this generations Perl.
- vor_ 14y agoSmall, fast, and easily embeddable in C programs. It's been popular in videogames for years but hasn't seen much usage outside that industry, so it's always interesting to see it used in different ways.
- eric_bullington 14y agoIt's very small, fast, and uses little memory. It's easy to learn and easy to interop with C. It's got two great implementations, with one (LuaJIT) probably holding the top spot among all dynamic, garbage-collected language currently in existence, measured by performance (although the creator -- `mikep` on HN -- is very careful to avoid making this sort of claim). It's also got one of the coolest GUI toolkits around in IUP. If you've ever wondered by a cross-platform GUI toolkit that uses native widgets has to be so huge and complex, IUP's what you're looking for. Unfortunately, IUP doesn't yet have a native OSX driver, but you can use motif graphics driver to build a program that will run on OSX. Like Lua, IUP's in portable C, so a number of other languages have built bindings, notably go and perl. Like Lua, IUP has a very liberal license license (MIT), so you can use it for commercial projects without worrying about dynamic or static linking.
- arundelo 14y agoCorrection: LuaJIT's creator Mike Pall is http://news.ycombinator.com/user?id=mikemike http://news.ycombinator.com/user?id=mikemike .
- eric_bullington 14y agoThanks for the correction. I should have verified the HN username for Mike; not sure where I pulled `mikep` out of since I always enjoy reading his comments here and elsewhere. It's too late for me to correct it in my original comment, so thanks again.
- swah 14y agoHe's mikemike on reddit as well.
- snogglethorpe 14y agoIUP seems cool in theory, but in practice, I've never even been able to compile/install it, despite trying multiple times over the years! Unfortunately the build system seems to be mostly of the "Works great on the author's system!" sort... >< I always try a bit to hack around the issues, but the problems have always exceeded my "oh this is too annoying, I'll try again next year" threshold (part of the problem being that it's an unusual build system, not just a few Makefiles, so it's less familiar).
- snogglethorpe 14y agoThis is a tweaked/updated version of a stackoverflow answer I wrote (see end for link) to someone wanting to know what language they should use for embedding: Lua, and Lua's standard implementation(s), capture a wonderful balance of features/smallness/speed/usability, particularly for embedded use. Lua: 1. Is very small, both source and binary, an order of magnitude or more smaller than many more popular languages (Python etc). Because the Lua source code is so small and simple, it's perfectly reasonable to just include the entire Lua implementation in your source tree, if you want to avoid adding an external dependency. 2. Is very fast. The Lua interpreter is much faster than most scripting languages (again, an order of magnitude is not uncommon), and LuaJIT2 is a very good JIT compiler for some popular CPU architectures (x86, arm, mips, ppc). Using LuaJIT can often speed things up by another order of magnitude, and in many cases, the result approaches the speed of C. LuaJIT is also a "drop-in" replacement for standard Lua: no application or user code changes are required to use it. 3. Has LPEG. LPEG is a "Parsing Expression Grammar" library for Lua, which allows very easy, powerful, and fast parsing, suitable for both large and small tasks; it's a great replacement for yacc/lex/hairy-regexps. [I wrote a parser using LPEG and LuaJIT, which is much faster than the yacc/lex parser I was trying emulate, and was very easy and straight-forward to create.] LPEG is an add-on package for Lua, but is well-worth getting (it's one source file). 4. Has a great C-interface, which makes it a pleasure to call Lua from C, or call C from Lua. For interfacing large/complex C++ libraries, one can use SWIG, or any one of a number of interface generators (one can also just use Lua's simple C interface with C++ of course). 5. Has liberal licensing ("BSD-like"), which means Lua can be embedded in proprietary projects if you wish, and is GPL-compatible for FOSS projects. 6. Is very, very elegant. It's not lisp, in that it's not based around cons-cells, but it shows clear influences from languages like scheme, with a straight-forward and attractive syntax. Like scheme (at least in it's earlier incarnations), it tends towards "minimal" but does a good job of balancing that with usability. For somebody with a lisp background (like me!), a lot about Lua will seem familiar, and "make sense", despite the differences. 7. Is very flexible, and such features as metatables allow easily integrating domain-specific types and operations. 8. Has a simple, attractive, and approachable syntax, which can be important if you intend to have end-users write scripts. 9. Is designed for embedding, and besides its small size and fast speed, has various features such as an incremental GC that make using a scripting language more viable in such contexts. 10. Has a long history, and responsible and professional developers, who have shown good judgment in how they've evolved the language over the last 2 decades. 11. Has a vibrant and friendly user-community. Stackoverflow link: http://stackoverflow.com/questions/7919763/lua-vs-embedded-lisp-and-potential-other-candidates-for-set-based-data-processi/7927730#7927730 http://stackoverflow.com/questions/7919763/lua-vs-embedded-l...