12 ms·
A History of Lua (2001)
- amilios 4y agoHonestly Lua is one of those languages that seems decently nice to use, fairly performant, and just makes me wonder why it hasn't been adopted for use more broadly in domains beyond just like being embedded in game engines. Am I missing something?
- spacechild1 4y agoLua has been designed as an embeddable scripting language and it is used as such in various domains and programs. It's not really suited for developing large applications, though.
- citrin_ru 4y agoYou can write largish standalone application in Lua and it is not always a poor choice - Prosody [1] first comes to mind. But qualities which make it a good embedded language make it less _attractive_ for other uses. Lua has very simple syntax and small stdlib which allows its implementation to be very small - you can add Lua to your application and not increase its size significantly. But when the size is not a concern most programmers prefer languages with rich, powerful syntax lots of features and batteries-included stdlib (which is completely opposite of Lua). [1] https://prosody.im/ https://prosody.im/
- orthoxerox 4y agoNo batteries included. It's designed to be embedded as a scripting language, so its stdlib is tiny. People managed to write web frameworks in Lua, but it's hard to snowball a good package collection when you've got Python and node next door.
- sam_lowry_ 4y agoIt is heavily used in some niche domains. Openresty comes to mind next to game dev. OTOH, it is too close to C and not really a breakthrough language like Rust or Go. As far as style and brevity goes, Lua wins hands-down, but who cares?
- aredox 4y agoIt's also used as the main scripting language in NeoVim. But if you want something more "out there", it's also the main language used to program open-source radio control remote (openTX) for drones/planes/gliders: https://medium.com/rc-soaring-digest/ive-got-the-power-opentx-871dade77895 https://medium.com/rc-soaring-digest/ive-got-the-power-opent... https://github.com/jfrickmann/SoarOTX https://github.com/jfrickmann/SoarOTX
- rahkiin 4y agoI’ve worked in a large Lua codebase, and its lack of any types gets very cumbersome. It is also non-trivial to get the full performance and by doing so lose some of the nicer features. For example, creating tables causes an allocation which is slow, so forget about using tables for vector types. These tables could have bad a metatype for operator overloading, but metatables cause multi-level lookups which is also slower. I could use it for some light scripting, but definitely would not write whole projects in it.
- spc476 4y agoAt work, I use Lua (and LPEG) to process SIP messages for the Oligarchic Cell Phone Company, processing calls in real time, and only once in the seven years it's been running did I have to tune the code. It certainly works for us.
- rahkiin 4y agoThat’s great :) I do think it has its place. We ran >200k lines of Lua for a 3d game at >60fps. We could not do allocations on the hotpath, or we would run out of our frame budget (which was around 1ms). Games are very hard to auto-test when not built with that in mind from the ground up, so any change to the code might unknowingly break any caller, and we would only know for sure once the game runs. Sadly the code base is 20 years old.
- kgeist 4y ago>For example, creating tables causes an allocation which is slow, so forget about using tables for vector types I once added vector4 as a primitive type in my fork of Lua (to avoid allocations altogether) - it was surprisingly easy to add, took me a weekend.
- rahkiin 4y agoWe were using LuaJit which is a whole other beast.
- otikik 4y ago
- leephillips 4y agoLua and lualatex allow access to TeX internals and (relatively) easy programming of typeset documents: https://lwn.net/Articles/731581/ https://lwn.net/Articles/731581/. Lua is the official language for writing Pandoc filters. And, of course, NeoVim. These are the contexts in which I use it; its embedding into TeX and Pandoc provides some powerful capability.
- ggm 4y ago> Lua is the official language for writing Pandoc filters Given pandoc is written in haskell.. an interesting choice. I guess investing in a DSL syntax was a cost too far.
- shadowofneptune 4y ago1. Each minor version of the language is distinct enough to be incompatible with the previous version. A project embeds one specific version of Lua and never upgrades it. 2. Since it is embedded, it has a pretty small standard library that the embedder can remove or extend. Both lead to Lua communities being more about individual projects which embed it.
- frou_dh 4y agoA good example of this is the Max/MSP audiovisual environment, which, amongst other things, has both Lua 5.1 and an ancient JavaScript engine (JaegerMonkey from Firefox 4) embedded in it to this day.
- lenkite 4y agoNo static typing, No ergonomic language features like lambdas, No functional programming, magic nil behaviour, global by default, no integer type (not sure if this was addressed), index tables instead of having a proper array/list type, missing switch, No assigning operators..the list goes on and on. It was an average PL a decade ago and it is simply mediocre now. Only superb implementations like LuaJIT prop the language up. I would prefer writing Enterprise Java (gasp) over writing Lua code for anything >5k lines. It's OK for small scripts but rapidly breaks down for anything larger. It's a bit funny that a complicated system PL like Rust is more comfortable to code than Lua. Only using Lua personally nowadays due to Neovim and now that https://github.com/noib3/nvim-oxi https://github.com/noib3/nvim-oxi has come out, I am going to use it even less.
- maegul 4y ago> now that https://github.com/noib3/nvim-oxi https://github.com/noib3/nvim-oxi has come out, I am going to use it even less. Woah, interesting ... provided there's success and uptake with this ... I'm imagining it could lead to a really slick and responsive editing experience that those of using (at least) slightly sluggish plugins might have been missing for a while now.
- fanf2 4y agoLua has had proper lexical closures and function expressions since 5.0 https://www.lua.org/manual/5.1/manual.html#2.5.9 https://www.lua.org/manual/5.1/manual.html#2.5.9 It has had 64 bit integers since 5.3 https://www.lua.org/manual/5.3/manual.html#2.1 https://www.lua.org/manual/5.3/manual.html#2.1
- Benjamin_Dobell 4y agoWhat do you mean by no lambdas exactly? Lua supports anonymous functions and they're in fact closures, since those functions capture variables from their outer scope. I use functional programming extensively in Lua also. Could you elaborate on what it doesn't permit? Integers were introduced in 5.3. Assigning operators? It has metatables, you can absolutely implement your own operators. If you want static typing you can use my IDE: https://github.com/Benjamin-Dobell/IntelliJ-Luanalysis/ https://github.com/Benjamin-Dobell/IntelliJ-Luanalysis/ Granted, my IDE is incredibly opinionated and not for everyone. Also, Lua is not my favourite language to use, doesn't even make top 3. However, the robustness of its design, considering its simplicity, is incredibly elegant.
- intelVISA 4y agoSome games use it for a UI/scripting layer but it's a nightmare to work with for anything complicated.
- cardanome 4y agoLua just doesn't have the marketing other languages have. No big corporation behind it. It does not have any exciting or frequent releases. It is basically done as a language since 5.1. New versions can be safely ignored, especially when you want to use LuaJit. These days people simply expect lots of churn and frequent releases to keep the hype for a language up. Also the current trend it towards static type checking which is especially hard to implement for Lua. There are some solutions for gradual typing but there is not exactly first-class support for that. The small standard library might also have been a problem in the past but these days I would argue that JS has normalized that part quite a bit.
- jhoechtl 4y agoIndex by 1
- remram 4y agoThis was such a weird decision. Lua is meant to be embedded, meaning it will have to call application code where indexes start at 0. Why make the Lua indexes not match?
- shadowofneptune 4y agoSome big influences on the syntax are Modula and Fortran. The first allows you to start an array with any index you like, the second starts it with one. As the article says, it started as a data language for engineers who may have been familiar with Fortran. The C-like languages were not as overwhelmingly common back when Lua started, as well.
- pull_my_finger 4y ago> When we started Lua, the world was different, not everything was C-like. Java and JavaScript did not exist, Python was in an infancy and had a lower than 1.0 version. So there was not this thing when all the languages are supposed to be C-like. C was just one of many syntaxes around. > And the arrays were exactly the same. It’s very funny that most people don’t realize that. There are good things about zero-based arrays as well as one-based arrays. > The fact is that most popular languages today are zero-based because of C. They were kind of inspired by C. And the funny thing is that C doesn’t have indexing. So you can’t say that C indexes arrays from zero, because there is no indexing operation. C has pointer arithmetic, so zero in C is not an index, it’s an offset. And as an offset, it must be a zero — not because it has better mathematical properties or because it’s more natural, whatever. > And all those languages that copied C, they do have indexes and don’t have pointer arithmetic. Java, JavaScript, etc., etc. — none of them have pointer arithmetic. So they just copied the zero, but it’s a completely different operation. They put zero for no reason at all — it’s like a cargo cult. https://habr.com/en/company/vk/blog/459466/ https://habr.com/en/company/vk/blog/459466/
- renox 4y ago
- otikik 4y ago> it hasn't been adopted for use more broadly in domains beyond just like being embedded in game engines It might not be in your particular awareness bubble. Parts of the infrastructure that transmitted the request that allowed you to post your comment (the most prominent one is Nginx, but routers and switches with Lua-scripting do exist). In my case, I work in Kong (which has a very healthy Lua plugin), I edit my code with Neovim (Lua is its main plugin-writing language). So I kind of "live and breathe" Lua. Still I am aware of other pieces of software that embed it that I don't use (Redis, Wireshark, even Wikipedia supports Lua on its templates). One interesting characteristic of the language is that it is "barebones". It doesn't have features that are "built-in" in other languages. Things like parsing a json file or making an http request. As a result, the "host program" needs to provide those. Which ends up making "flavor Lua" - Lua with certain assumptions about the host. In this way, Lua is not "one big continuous landmass", but instead an "archipelago". This lack of central point makes it impossible to attach a "marketing/hype machine" to it. It's more like a silent revolution, the language stands on its own merits, for better or worse.
- hulitu 4y agoI was compiling a game which needed Lua. Lua used its own make system without config files which failed with an obscure error message. Since then i avoid it.
- babarock 4y agoLua used to fill a niche very similar to Javascript: small lightweight OOP language that focuses on being embedded in a larger C program. Javascript won this war, mostly based on the explosion of the Web and the insane optimization work that was put on JS engines during the late 2000s. JS ate Lua's cake, not on pure technical merits (the two languages are very similar) but because of their respective environments.
- runevault 4y agoFor reference JS isn't actually object oriented, it is a prototype language. You can fake it being OOP within that style, but it isn't really OOP, even if you can code in it that way.
- Atomskun 4y agoJust like Lua, hence their similarities.
- runevault 4y agoThat's fair. I didn't realize Lua was also a prototype language as I've barely looked at it. Been curious but it never fit my current set of curiosities.
- babarock 4y agoIf we want to be pedantic, prototypal inheritance is a kind of OOP[1]. What you're talking about is referred to as "classical OOP" (OOP using classes). [1]: https://en.wikipedia.org/wiki/Prototype-based_programming https://en.wikipedia.org/wiki/Prototype-based_programming
- SulphurCrested 4y agoThe first paragraph in the introduction claims the "failure to fulfill expectations" of Algol 68 and Ada were because they were designed by a committee. Leaving aside whether they were or weren't disappointments, neither was really designed by a committee. Algol 68 was famously presented as a fait accompli to the IFIP committee by Adriaan van Wijngaarden, as documented by Dijkstra and leading to the minority report and ultimately Wirth's Algol W and then Pascal. Ada was largely designed by Jean Ichbiah, and all the various committees of the US DoD did were choose his design over the competitors. Both languages strongly appealed to me, probably because of their cohesive (one-man!) designs, although I never got the chance to use them professionally. So I do agree that a strong, usually one-person, design is the way to go. But both Algol 68 and Ada failed for other reasons. I'm speculating, but I suspect they simply required too much of the average programmer: mathematical sophistication in the case of Algol 68, and discipline in the case of Ada. The other plank of TFA's argument is that successful languages are built up slowly based on experience of requirements. I think if such a language ends up any good, it's either luck or someone spending a lot of effort pushing back on bad proposals. I'm sure you too have a list of languages in mind which grew in an undisciplined manner, until they strangled themselves. I think of language designers who allow that as like Maxwell Smart in Control headquarters, running coloured strands of wool between pushpins on a map until it's a woolly mess. I suspect what really made Lua a success is it found users among game developers at the right time in its development, and did not try to be much more than that. In that sense, by listening to users and adding things, they achieved a good design (I assume – I don't really know the language), and because it did not achieve wild success that constituency of users was not so diverse as to baroquify the language. A language can fail if it is a clean design but doesn't have users (Eiffel). A language with an ugly, committee, design can succeed if it has users (C++).
- wruza 4y agoI was lurking in their mailing list for some time and they push back a lot, I’d even say they managed to create a culture of no-feature. Whether it was good or bad idk, because (as expected) some proposals sounded good to me, some so so. What makes Lua unpopular imo, beyond subjective trivialities, is that they break compatibility in every version and in fact they release flavors of the same core idea vs updates of a language. Also it is technical and not user-friendly for windows users, because luarocks (package manager) is unusable there unless you’re skilled in C build systems and are ready to fix these issues. I lost track of it at 5.3. I think Lua would feel much better if it stopped at 5.2 (or even at 5.1, fixing the shortcomings in 5.1 way) and took care of what’s called ecosystem, emerging around its game popularity.
- catdawg 4y agoI've worked now for 3 years on a large lua game code base, over 4000 files, 1.5 million lines of code. In the first week or so, I was a bit weirded out by the lack of language features, as I come from C#/Typescript/C++, but I was very surprised that after 2 or 3 weeks, I was already doing very complex tasks on the code base. I think a lot of that comes from the simplicity of the language. It's very difficult to surprise you, everything works in pretty much the same way. Here are some things that I will miss once I move to other languages: (note that most of these are not things that come from simply using lua, you have to implement it into your framework/engine, but they are still pretty common) - stack traces print the contents of the variables in the stack. Not all lua code bases have this, but it is easy to implement. - if the code crashes, you can fix the code and continue. This doesn't always work, and requires the code base to be written in a way that supports it, but it is definitely possible and I've used it many times. - debugging works really well. You can easily attach and inject code, stop on exception and inspect the state. - settings are also lua code. This is probably the biggest thing I'll miss. I love being able to have simple functions as part of settings (e.g. things like tweening functions), being able to generate settings based on other settings, or run simple sanity checks, all on the same file. - index starting on 1, this is definitely an unpopular opinion, but IMO it just makes things so much easier. When you need to access the last element, you just do tbl[tbl_length], no need to decrease by 1, or doing a for loop, you only specify the indices you're actually accessing "for i = 1, last_index do end". I think it really helps with off by 1 errors. I used "normal" indices for over 10 years before this project, and I would still occasionally have these errors, but with lua, I don't really remember having them. - not having to fight the compiler to quickly try out different things. Need something from a completely different system? Just add it to the global table and access it from the other place. A big learning I got from transitioning from languages with a very strong type system to a dynamic language like lua, is that in order to be effective, you really need to use code architecture patterns, otherwise things become very hard to reason with. This might be counter intuitive, but I think you need to be a better programmer to use lua effectively, than you need to with a language like C# or Typescript. With the latter languages, the compiler helps you a lot, but with lua, you have to know how to use these things on your own, because you can pretty much do anything and that can be reeeeally bad :)
- 4y ago
- deleted 4y ago[deleted]
- andrewmcwatters 4y agoMy favorite feature of Lua is that it tells you who all of the complexity-loving people in the room are and those who enjoy syntax monocultures. Almost every single time, without failure. I consider its simplicity and the fact that people merely complain about its syntax as highlights of an extremely thoughtful piece of software. I have complaints about its use for threaded work as well as performance, but it’s relatively hard to run into issues with the language in regular practice. I don’t buy the lack of types argument in any programming language to be a compelling argument. Maybe consider that you or other authors you’re working with are bad at writing software. It’s a more boring conclusion and more often more accurate.
- Banana699 4y ago>I don’t buy the lack of types argument in any programming language to be a compelling argument. Maybe consider that you or other authors you’re working with are bad at writing software. I don't buy the lack of seatbelts argument in any car to be a compelling argument. Maybe consider that you or other drivers you're driving nearby are bad at driving.
- lobstrosity420 4y agoTypes are more like that annoying chime that beeps when you have the door open.
- emehex 4y agoI think this is only true for a language like Python, or TypeScript, where types are second class citizens… For me, using types in Swift is sort of like “NOS” in that it’s helped me go faster (and further”!
- scaredginger 4y agoI still find typing in Python and TypeScript hugely beneficial, even just for how it makes my editor work better. Being able to click to a definition does wonders for reading unfamiliar code
- krapp 4y agoI really wish LuaJIT was the standard for Lua. Lua with a C FFI makes it so much easier to work with C libraries like SDL, as opposed to writing Lua bindings from within C. Lua alone is great, but being able to write C structs in Lua and overload operators is chef's kiss. Of course you can ignore this opinion if you're one of those people who believe C is an abomination to God whose blight should be stricken from the world. To each their own, but for me, Lua is the best C framework out there. Lua is also my go to suggestion whenever threads about which language to use for configuration come up. The syntax of lua tables are basically JSON, except without quoting keys and with comments. And the overhead of embedding it is likely close to nil compared to the interpreter for YAML or whatever. It's a nice language. Wish I had something more profound and complex to say about it. I would just suggest considering JuaJIT if you ever do need to work with C and it's allowed. Or just Lua if you're a masochist and want to deal with the stack.
- naniwaduni 4y ago> I really wish LuaJIT was the standard for Lua. Lua with a C FFI makes it so much easier to work with C libraries like SDL, as opposed to writing Lua bindings from within C. Lua alone is great, but being able to write C structs in Lua and overload operators is chef's kiss. Of course you can ignore this opinion if you're one of those people who believe C is an abomination to God whose blight should be stricken from the world. To each their own, but for me, Lua is the best C framework out there. Honestly, I keep finding LuaJIT's FFI to be profoundly disappointing. It falls into the common FFI trap of support, essentially, a C ABI—sure, it parses C declarations, but without preprocessor support and no good way to ask for, say, "just get me all the declarations from errno.h", it cannot work with the universe of code that expects you to pass in e.g. symbolic constants provided in a C header, or preallocated structs, or via preprocessor macros, that maintains compatibility only at the C source level. It's not an easy problem, to be sure, short of doing the C++ thing and embedding most of C outright.
- krapp 4y agoYes, it's not perfect, but I think it's better than Lua on its own (assuming you don't need anything newer than 5.1)
- jhatemyjob 4y agoNo mention of LuaJIT
- jamesgeck0 4y agoPresumably because this document was written four years before LuaJIT was developed.
- spc476 4y agoAnd LuaJIT is from another author, Mike Pall from Germany (Lua itself is from Brazil).
- einpoklum 4y agoWhy only the history until 2001? What about the years since then?
- daneel_w 4y agoAt work we make plentiful use of Lua on our telephony backend. As part of many dial plans we need to invoke certain "scripty" functionality - stuff that runs top to bottom to do one thing and then return - which may require e.g. database access, RabbitMQ interaction, Memcached key wrangling etc., and Lua's fast start-up and executional speed facilitates this for us on large scale better than almost anything else. We initially began with Python for some of these things, which quickly became an untenable and elaborately consummated performance disaster. There are plenty of techniques to get around its slow start-up and performance issues, but they come with a slew of new complications compared to the simplicity and ability to quickly deploy/update/execute from local file system. Lua for us makes the difference of being able to, on one and the same piece of hardware, manage a thousand simultaneous phone calls instead of just a few hundred.
- jpe90 4y agoI recently learned lua and wrote an alternative to bat that outperforms it by an order of magnitude. I thought Rust was supposed to be fast! :) https://jeskin.net/blog/clp/ https://jeskin.net/blog/clp/ Love the language!
- JonChesterfield 4y agoLua is my tool of choice for code generators in C projects. Not the intended use case for the language but it's very good at it, and a single file lua.c built along with the rest of the project is no bother.
- qikInNdOutReply 4y agoI did that too.. so fast to setup some definition generators, its really lovely.
- luanilnotnilyay 4y ago
- andrewshadura 4y agoVery interesting, the authors find Tcl syntax highly cryptic.
- badsjan 4y ago
- giraffe_lady 4y agoYeah my experience as well. I've worked in lua for years and nearly every codebase has a home grown, often incomplete or fairly bad implementation of a json parser, csv writer, rgb converter, templating engine, etc. Only old-school php rivals it in this. And for some reason this language seems to provoke people into writing custom build systems. A huge number of lua projects have them. In practice make can be pretty bad too but at least it's bad in familiar ways.
- JonChesterfield 4y agoLua itself is _really_ good as a build system. Spawn a process with libuv, wrap it in a coroutine to periodically check on progress, done.
- WalterBright 4y agoWe were very pleased that Roberto Ierusalimschy came to DConf last week and gave a great talk on Lua! https://dconf.org/2022/index.html#robertoi https://dconf.org/2022/index.html#robertoi https://www.youtube.com/watch?v=04gJXpJ1i8M&t=1711s https://www.youtube.com/watch?v=04gJXpJ1i8M&t=1711s
- dottrap 4y agoWow, I just watched the video and was surprised and delighted to see Roberto talk about Pallene (typed & compiled sister language for Lua). Fantastic!
- rukiwang 4y agoApart from c, lua is my favourite language. c + lua is the perfect combination and I have developed a lua-based build system using them. https://github.com/xmake-io/xmake https://github.com/xmake-io/xmake