9 ms·
The evolution of Lua
- generateui 15y agoWarning: this links to a PDF.
- zdw 15y agoUsually PDFs get reposted to Scribd or a similar service - it's somewhat unusual that it wasn't in this case.
- icebraining 15y agoStrange but much appreciated!
- pasbesoin 15y agoPerhaps the trailing octothorpe (#) threw off the HN functionality that does this. Noteworthy.
- pacomerh 15y agoInteresting for me to know that Lua has been used seriously for game development. What are the main limitations?, how come people aren't developing more in Corona rather than straight objectiveC. I'm guessing the Corona environment itself is the limitation?.
- malkia 15y agoYou just said that you've just learned about lua used in games, and then directly propose Corona as the only place where you can use lua. You can embed yourself lua, and that's it's power. It can go down to 30-40kb (without parser), and run on PS3 SPU chip (256kb memory). It does not use any globals, all goes through a state structure, so you can have multiple runtimes (and different ones, HavokVM, lua reference, luajit) if you want at the same time. Don't get me wrong, Corona is cool, but there is also moai, and tons of other toolkits, and hundreths of other games that are using it - for scripting, ui layout, configuration, many other things.
- Derbasti 15y agoLua is pretty minimalistic. There are few batteries included. The standard library is very basic. There is no native object system, though implementing one is trivial. That said, I friggin love Lua for its flexibility and transparency. Once you grok its few basic mechanisms, everything else just falls in place. In contrast, understanding Ruby or Python is a lot more difficult since the languages themselves are a lot more complex. In fact, if I were to teach programming, I would teach it using Lua. Implementing your own object system is increadibly instructive. Learning about coroutines and lambdas is, too. And Lua is still small enough to just read its source when in doubt. It's bytecode consists of just a few dozen instructions. Honestly, Lua is a marvellous language and I just love to use it!
- RegEx 15y agoDo you have any recommended resources for programmers looking to pick up Lua?
- anonymoushn 15y agoProgramming in Lua seems to be the best choice, but mostly by virtue of the very small number of coices. It was most recently printed in 2006, but there were few breaking changes since then, and you won't run into them very often. To be honest, I learned it using only the tutorial here: http://lua-users.org/wiki/LuaTutorial http://lua-users.org/wiki/LuaTutorial and google.
- telemachos 15y agoRoberto Ierusalimschy's Programming in Lua, 2nd Ed. is an absolute gem. Well written, concise and very authoritative (he's one of the language's co-creators). One thing worth knowing though: he's working on the 3rd edition (updated for Lua 5.2), though I'm not sure how soon that is expected. The first edition is online, if you want to get an idea what it's like: http://www.lua.org/pil http://www.lua.org/pil. In addition, the language's refrence manual is freely available online as well. Depending on how you learn, that would get you started very quickly. (It's a small language and very much follows the principle of least surprise - except for indexing arrays from 1, but you get used to that.) http://www.lua.org/docs.html http://www.lua.org/docs.html has the full reference manual for 5.1 and 5.2.
- forrestthewoods 15y agoLua is indeed widely used in games. The plus is that it's a very simple language to pickup and anyone on the team can learn to use it. The downside is that anyone on the team can use it. :) Memory is an extremely rare commodity in embedded systems and Lua loves to gobble it up. Consistent perf in video games is crucial and the Lua garbage collector can be brutal in this regard. Newer versions of Lua support incremental garbage collection but it's quite realistic to dedicate 2-3 milliseconds of every frame to garbage collection. Yuck. (16ms = 60fps, 33ms = 30fps) Lua is trivial to implement into an existing engine. Lots of iOS engines heavily rely on Lua. Large games devs don't want to become reliant on those middleware engines. It can take them many months to update to latest iOS sdk. It took several popular engines 6+ months to integrate the in-app purchase SDK update. Havok, owned by Intel, purchased Kore and turned it into Havok Script. Havok Script is a virtual machine that runs a "Lua compatible" language. It is extremely fast. Ridiculously faster than straight Lua. It also has full debugging support and you can trivially step through a call stack that bounces between C++ and script. Havok middleware is not known for being cheap.
- pjin 15y agoluajit2 in interpreter mode is also very fast, originally written in x86 (Mike Pall has probably finished the arm port by now). But I've never heard of any benchmarks between the luajit2 interpreter v. havokVM, that would be interesting to see.
- tomlu 15y agoKeep your eyes peeled for a port of the LuaJIT interpreter to the consoles. From recollection it's two or three times faster than straight Lua.
- emmelaich 15y agoI think you'll find many if you look. It occupies a nice slot between the speed and control of C and the ease (and slowness) of python, java etc. Codea, app development in iPad for iPad uses lua. It was recently mentioned on HN. Computercraft, a mod for minecraft embeds lua in minecraft for you to program. Not a direct use of lua in gaming, but cute!
- NickPollard 15y agoLua is used largely in AAA development. Most famously, it powers the UI for World of Warcraft, and users are able to write their own complete UIs in Lua. Many other games use it for scripting. When I worked at Sony, we were using it on quite a few PlayStation games.
- anonymoushn 15y agoI was surprised to learn that coroutines were new in 5.0 until I also learned that 5.0 was released in 2003.
- telemachos 15y agoIf you enjoyed this, you will probably also like the same author's "The Novelties of Lua 5.2"[1]. [1] http://www.inf.puc-rio.br/~roberto/talks/novelties-5.2.pdf http://www.inf.puc-rio.br/~roberto/talks/novelties-5.2.pdf
- gruseom 15y agoI absolutely love how they are making such major changes as late as version 5.2. I also love that one of them is goto. Lua is terribly impressive. Someone needs to make a transpiled language targeting Lua and JS. They're semantically close enough that this might not be too complex. If it worked well, it would be an interesting alternative to Node.js, since you could write the server-side for Lua coroutines and so on. Not to mention its performance.
- catch23 15y agoLua does have lots of metaprogramming that js lacks, and adding into js could be tricky since you'd essentially have to rewrite existing js code into new code that allows this. However, the grammar rules are fairly convertible. I've converted a parser that normally targeted javascript, to target lua instead (it was for a project to convert lua code into json).
- gruseom 15y agoThe easy way would be to make a language that compiles to the semantic intersection of Lua and JS; that is, don't expose things that you can't easily generate both Lua and JS for. Such a subset would cover approximately everything I for one want to do in JS anyway. You could make it easy to take advantage of Lua-only features like metaprogramming by denoting them server-side only. You'd have to do that to get coroutine support anyway. The idea seems so exciting and obvious that I wish I had time to do it. Lua doesn't seem to be used much for server apps, though. Why? Are there technical limitations that make it unsuitable, or is it just that it hasn't been exploited yet? Another thing I'd like to know, given how embeddable Lua is, is whether one could embed it as a browser plugin and then get the power of Lua client-side as well. Obviously, one wouldn't demand this of users, but it would be a pretty sweet option to offer: "install this little plugin to make the program faster and more responsive". One final thought. I wish Google had gone with Lua instead of making Dart. Lua is basically JS done right. Seems to me they could have built a compelling case around it.
- Difwif 15y agoI have such a strange love for Lua. It was one of the first languages that I learned and used to program homebrew for the PSP. It's really where my journey as a programmer began and was the first language that I programmed with for fun. I don't think you can ever stop loving the first language you got your hands dirty with.
- vbtemp 15y agoUnless of course it's C++ </personalopinionwithouttryingtoinstigatereligouswar>
- Twisol 15y agoTechnically, my first programming language was C++, and I really don't love it. ;) But that might not count: I actually started with a markup language, HTML, which I use daily. </sameDisclaimer>
- haberman 15y agoAs someone who values simplicity, minimalism, portability, and good performance, Lua is a constant source of inspiration to me. I frequently look at its design for ideas.
- gruseom 15y agoPlease say more. What are some inspiring things you've found in Lua's design?
- haberman 15y agoI'm having trouble answering your question eloquently. I'll think about it more and hopefully write a blog post about it before long.
- gruseom 15y agoPlease do. I'd like to read it. It seems to me the outstanding feature of Lua's design history is its designers' determination to make the core ever simpler and more general. That takes vision and courage over a long period of time. What emerged is truly interesting and inspiring (much more so than cobbled languages that grow only by accretion of features) and is likely to grow in importance.
- haberman 15y agoYes, that is very much how I feel about it. They boil every concept down into its purest essence, and always avoid having two abstractions when one will do. Other languages grow when they need new features, Lua refines. But in a blog entry I'd like to address several of Lua's core abstractions and how they are cleaner and more general than competing languages. For example, the Lua thread data structure encapsulates all necessary state for a thread, but is general enough that it actually allows for multiple thread execution models. By default only coroutines are provided (which use the thread data structure). But you can implement lua_lock()/lua_unlock() to have a Python-like model with preemptive threads and a GIL. Or you can use lua_sethook() to implement a "green thread" model where multiple pre-emptive Lua threads run inside a single OS thread. Three options for threading models (probably more if you dig in), one core abstraction and implementation. Remarkable!
- bitcracker 15y agoOne serious thing Lua is still missing is native Unicode support (correct me if I am wrong). When I discovered Lua the first time I was enthusiastic. The JIT is so fast, and everything seems to be fine. But missing Unicode is a big disadvantage for Lua. Unicode is a must to have for modern languages. It makes things so much easier when you know you don't have to convert any fonts because they are all presentable in Unicode.
- jballanc 15y agoAfter having worked with Ruby 1.8 (no unicode support in String) and Ruby 1.9 (added unicode) rather extensively, as well as C/Obj-C and a variety of other languages with varying ideas on Unicode support, I am of the opinion that Lua has the right approach. If your built-in string type does not account for encodings, you can always build one on top of it that does. If, on the other hand, your built-in type has to carry the constant burden of encoding information, you'll never get away from that (indeed, I've been talking with ruby-core about adding back a string-like library with no encoding information in Ruby 2.0).
- bitcracker 15y agoAs long as you handle usual letters it is no problem to miss Unicode. How nice Unicode is I always realize when I copy and paste some foreign text from somewhere into Emacs or Racket Scheme and everything works just fine.
- groovy2shoes 15y agoWhat he's trying to say is that Lua's strings are capable of storing Unicode characters (they're "8-bit clean"), but that Lua's string manipulation functions aren't Unicode-aware. If you want to paste Unicode characters into a string and print it later, Lua can handle it. If you want to do a pattern match on a Unicode string, you need to bring your own pattern matcher.
- tomlu 15y agoThe idea of adding at least some rudimentary UTF-8 support has been gaining traction on the Lua mailing list. So maybe for the next version of Lua you'll see some sweet Unicode.
- j4mie 15y agoOne thing I didn't like after a quick look at Lua is that all variables are global by default. j = 10 -- global variable local i = 1 -- local variable ( from http://www.lua.org/pil/4.2.html http://www.lua.org/pil/4.2.html ) Same with functions. To declare a function that is restricted to the local scope, you must explicitly use "local": local f = function (...) ... end Can any Lua aficionados explain why this is the case? Surely a better design would be for variables to have local scope by default, and to require an explicit "global" prefix to be globally visible? Does this ever cause problems in real-world code?
- charltones 15y agoI did a fair amount of real world Lua a few years ago. This issue did start to bother me after my codebase grew. It is fairly easy to work around, mainly due to the very powerful metaprogramming facilities in Lua. See http://lua-users.org/wiki/DetectingUndefinedVariables http://lua-users.org/wiki/DetectingUndefinedVariables. I ended up adding a few lines of code to my own common library module which disallowed globals unless specifically declared with my own "declare" function.
- jballanc 15y agoThere's a page on the Lua users wiki that neatly summarizes the various arguments: http://lua-users.org/wiki/LocalByDefault http://lua-users.org/wiki/LocalByDefault Essentially, instead of asking "why global by default", you should have to explain "why local by default is a good idea". In practice, I've found it something easy enough to get over. You don't have to believe me, though...give the Lua Missions a try and see if you don't like Lua just a bit more than you thought you might: https://github.com/kikito/lua_missions https://github.com/kikito/lua_missions
- cygx 15y agoLocal or global by default is the wrong question to ask, because implicit declarations are a bad idea either way. Io - another minimal language - avoids the issue by having different operators for definition (:=) and assignment (=).
- 15y ago
- Angostura 15y agoIf you want to tinker with Lua, Codea on the iPad lets you code in it and create little iPad apps (for your own enjoyment).