27 ms·
What's New in Lua 5.4
- gautamcgoel 6y agoLua is a language I really want to love. I like the emphasis on simplicity and minimalism, and the Scheme-like semantics, which mix imperative and functional styles, really hits a sweet spot IMO. LuaJIT is a crazy impressive feat of software engineering. However, there are some specific issues which hold Lua back IMO. First, as LuaJIT author Mike Pall famously noted, the Lua authors constantly break compatibility between releases. Lua is really several different, incompatible languages (Lua 5.1, 5.2, etc). LuaJIT is still at Lua 5.1, IIRC. Second, there are a bunch of minor nitpicks (1-based-indexing, anyone?) which turn off a bunch of people. Lastly, because Lua is so minimal and focused on portability, people end up reimplementing their own abstractions (such as object systems) from scratch, further fracturing the ecosystem. I think there's a space for a new project, which takes LuaJIT as a starting point and addresses some of the issues I described. It would also be great if this hypothetical new language had better support for Unicode and concurrency.
- ebg13 6y ago> LuaJIT is still at Lua 5.1, IIRC It's 5.1 plus some of 5.2.
- bch 6y agoIf you’re not already familiar, check out Tcl. It’s well established, similar domain, and addresses some of your concerns head-on - very stable API/semantics, not 1-based, comes with quite a few “batteries” included, excellent concurrency and parallelism (lovely thread model (apartment [0])), native Unicode... but still portable and actively developed. [0] http://www.opengroup.org/comsource/techref2/CHP06GDC.HTM http://www.opengroup.org/comsource/techref2/CHP06GDC.HTM
- google234123 6y agoTcl code always looked ugly to me
- the_hoser 6y agoTCL is... semantically, amazing. It is syntactically hideous. As much as we like to claim that we're technical people and form over function blah blah blah... aesthetics and readability matter.
- virtue3 6y agoone of my professors described TCL as "what a bunch of grad students made for a programming language". Always got a chuckle out of me.
- the_hoser 6y agoPretty close. It was a professor that was tired of people writing languages to embed in their applications, so he wrote a language to embed in applications. Very much an XKCD 927 story.
- bch 6y agoThe guy who also brought us raft[0], log structured file systems[1], and Ousterhouts Dichotomy[2], among other things, in case you were thinking “not a bunch of grad students, but ‘some professor’.” [0] https://en.wikipedia.org/wiki/Raft_(computer_science) https://en.wikipedia.org/wiki/Raft_(computer_science) [1] https://en.wikipedia.org/wiki/Log-structured_file_system https://en.wikipedia.org/wiki/Log-structured_file_system [2] https://en.wikipedia.org/wiki/Ousterhout's_dichotomy https://en.wikipedia.org/wiki/Ousterhout's_dichotomy
- the_hoser 6y agoI figured that details like that didn't matter in the context of the joke. He was a smart and productive person that designed an ugly programming language.
- petre 6y agoIt's also quite slow.
- pansa2 6y ago> I think there's a space for a new project, which takes LuaJIT as a starting point Unfortunately, LuaJIT is tightly-coupled to the Lua language and its code is very complex. I'd be surprised if anyone other than Mike Pall was able to retarget it to support a different language. Also, is JIT compilation really necessary for a scripting language? Projects like the PyPy JIT for Python have seen little adoption, and many platforms (e.g. iOS and game consoles) don't support JIT at all.
- jashmatthews 6y agoCompared to other JIT compilers LuaJIT is very simple. Thomas Schilling forked LuaJIT to run Haskell with what looked like some good results http://files.catwell.info/misc/mirror/tracing-jit-haskell-schilling.pdf http://files.catwell.info/misc/mirror/tracing-jit-haskell-sc...
- Rochus 6y ago> Compared to other JIT compilers LuaJIT is very simple. Wow, the understatement of the year.
- Rochus 6y ago> I'd be surprised if anyone other than Mike Pall was able to retarget it to support a different language. Not that difficult. See e.g. https://github.com/rochus-keller/Oberon#lua-source-and-bytecode-generator-features https://github.com/rochus-keller/Oberon#lua-source-and-bytec..., https://github.com/rochus-keller/Smalltalk#a-smalltalk-80-interpreted-virtual-machine-on-luajit https://github.com/rochus-keller/Smalltalk#a-smalltalk-80-in..., or here a whole list of other language frontends: https://github.com/hengestone/lua-languages https://github.com/hengestone/lua-languages
- pansa2 6y agoSorry, that's not quite what I had in mind. I was considering the feasibility of modifying LuaJIT to directly target a different language. The projects you link to all either compile to, or are written in, Lua source code or LuaJIT bytecode. That's less efficient than retargeting the LuaJIT VM. For example, LuaJIT includes bytecode instructions specifically tailored to Lua tables. It looks like these projects build, say, their array data structures on top of those existing instructions, rather than adding array-specific support to LuaJIT.
- Sophistifunk 6y agoWhat you're looking for is the JVM.
- sriku 6y agoJulia also has 1-based indexing .. You get used to it pretty quickly.
- markrages 6y agoYes, you just crap up your code by subtracting 1 anywhere you need to calculate an index. I moved from Matlab to Python and the biggest improvement was zero-based indexes.
- pjmlp 6y agoJust like you do with the upper index in zero-based languages , as length > max index. Apparently this little detail is never taken into account.
- Reelin 6y ago> You get used to it pretty quickly. You don't if you're writing low level algorithms. It's difficult for me to articulate the exact problem but I liked 1-based indexing until I needed to implement some algorithms that operated on multi-dimensional arrays element wise. Things just don't compose the right way. It's actually the primary reason I don't make more use of Julia. I like the syntax and overall design more than Python but it just isn't worth it to me. (If you're wondering what I'm doing in an Lua comments section, it's because I really like the ideas behind some of the Lua based languages such as Terra.)
- henrikeh 6y agoI primarily work in 1-indexed languages, but I think everyone is missing the forest from the trees in this discussion: indexing should be selectable by the programmer. One or zero indexing is a question about domain and communication. In signal processing, it is quite normal to need a negative index (autocorrelations f.x.). Ada (and I believe Pascal and Julia) has supported for specifying the indexing type, which can then be selected to match the problem domain.
- google234123 6y ago
- jhoechtl 6y agoYou have all my upvotes. I really would like to like Lua but the lack of the mentioned basic infrastructure elements like powerful Unicode support and platform-independent parallelism abstractions make every larger Lua project a DSL of it's own.
- anonymoushn 6y agoIn Openresty you don't end up facing much trouble around parallelism. In other contexts, I might go for love2d's thread module, which can be loaded from liblove on its own https://love2d.org/wiki/love.thread https://love2d.org/wiki/love.thread I've had an ok using unicode libraries but I haven't had to do much with them so far.
- rjeli 6y agoVery nice, congrats to the Liz team :) The new `const` and RAII/resource scope language features remind me of the golang discussion yesterday, someone linked Pike saying JS/TS, C++, Hack, etc keep borrowing features from each other. Of course we won’t fully converge on some perfect syntax any time soon, or ever, but we seem to be settling into a general consensus on syntax in general, and semantics of dynamic languages.
- blibble 6y agoI used to quite like Lua, but got quite consistently wound by up several things - global variables by defauilt - weird choice of certain operators (~= for not equal) - arrays start at 1 (fixed yet?)
- ebg13 6y ago~= and 1-indexing are only weird if you haven't seen them before. MATLAB uses them as well.
- sk0g 6y agoIsn't "weird == not seen it before" anyway? I get what you're trying to say, but MATLAB is not really a programming language SWEs would use, so if that's the best example you can think of, Lua's bound to confuse most people in the industry. May work better for mathematicians, non-SW engineers etc, but I wouldn't know.
- rpdillon 6y agoJulia is 1-indexed as well.
- luhn 6y agoWhich is also targeted towards scientific computing.
- ebg13 6y ago> I get what you're trying to say, but MATLAB is not really a programming language SWEs would use It may not be a language that website jockeys use, but "I don't use it therefore probably no one does" is almost never correct. MATLAB is huge in state machine and dynamic systems programming as well as being the original commercial powerhouse for linear algebra algorithms.
- sk0g 6y ago
- Analemma_ 6y agoI've heard that a major use case for Lua is to enable scripting in game engines - for something like that, it sounds perfect, because the entire runtime is just a couple thousand lines of C with few dependencies, that can be literally copy-pasted into your codebase if need be. But honestly, I can't recommend Lua for any other use case. You'll be chugging along and then run into a brick wall when you need e.g. real regexes instead of Lua's comparatively crippled pattern matching, or a networking library that isn't hosted on one professor's personal web page that hasn't been updated in years. Take it from someone who had to throw out and port a bunch of Lua scripts when they just couldn't keep up with new business requirements: Python or Perl or Ruby is almost always a better choice.
- anonymoushn 6y agoI'd probably use PCRE there. Every C library becomes a Luajit library when you run the relevant header through the C preprocessor and paste the result into your code. Sometimes you have to do this yourself, which makes it more work than you'd need in Python though.
- sago 6y ago> I've heard that a major use case It was. At peak perhaps 10 years ago. It is telling that the game engine citation in that article is from 2009. Now the ecosystem of game engines is very different. Very few games are written in raw C/++ and have to have their own tiny scripting language packaged. They are mostly based on more established engines. 'Small studios' have gone, niched out of end-to-end dev, or re-invented as the 'indie game' world, and pretty much none have their own multi-game engine. In fact, I've only come across Lua used in Pico-8 gamejam games in the last 2 yrs, personally. (Though I'm retired now.) It was a phenomenal language for gamedev. I commissioned a Lua consultant to extend the language in a small way for a game, I ended up paying for about half the hours I expected.
- deleted 6y ago[deleted]
- pansa2 6y ago> It was. At peak perhaps 10 years ago. Yeah, I wondered if that was still the case. Most of the examples I can find of “games that use Lua” are indeed around 10 years old. Are more recent games using different scripting languages, or are they designed to not use a scripting language at all?
- didip 6y agoI always thought Lua would be great for config files. Better than YAML even, since it's an actual language. Imagine if Kubernetes config files are actually Lua files.
- seany 6y agoYou can do that with nginx https://docs.nginx.com/nginx/admin-guide/dynamic-modules/lua/ https://docs.nginx.com/nginx/admin-guide/dynamic-modules/lua... . IIRC Cloudflare uses this extensively.
- lioeters 6y ago> Cloudflare uses this extensively Thanks for this mention - I found: CloudFlare repos on GitHub using Lua: https://github.com/cloudflare?q=lua https://github.com/cloudflare?q=lua Blog posts with "Lua" tag: https://blog.cloudflare.com/tag/lua/ https://blog.cloudflare.com/tag/lua/ Pushing Nginx to its limit with Lua - https://blog.cloudflare.com/pushing-nginx-to-its-limit-with-lua/ https://blog.cloudflare.com/pushing-nginx-to-its-limit-with-...
- jgrahamc 6y agoWe make use of OpenResty and LuaJIT although we are moving away from them and more and more towards code written in Rust and other languages.
- davidgould 6y agoLua was originally invented as a way to describe complex data. At some point it was enhanced with executable data and from there it’s a small step to become a programming language.
- xud 6y agoI don't think it's a good idea to make config files complicate. I don't want to run a debugger to know how my configuration file works.
- krapp 6y ago
- edsiper2 6y agoLua is just great. In Fluent Bit[0] we expose Lua filter capabilities. So end-users can write their own scripts to manipulate record logs and accommodate keys/values easily with a simple programming logic: - https://docs.fluentbit.io/manual/pipeline/filters/lua https://docs.fluentbit.io/manual/pipeline/filters/lua I am happy to see performance is being improved, as of now we stick to LuaJIT, since our use case is pretty simple we have not found a good reason to move away from it. [0] https://fluentbit.io https://fluentbit.io
- tedd-the-tiger 6y agoA link to subscriber-only content on a public news site?
- Pxtl 6y agoI love Lua for its architecture and goals, but not for its linguistics... and this is more of the same. The platform is getting even better, but I feel like the language is getting worse. <const> and <close> are kinda hideous, aren't they?
- aquova 6y agoI had heard that Lua was adding const support, which I was excited for, but I hadn't seen the syntax until now. I don't care for it. I'm guessing this is due to ambiguity as to whether variables declared as const would be local or global, but I would rather have something like const x = 1 local const y = 2 over what they're adding.
- ufo 6y agoThe problem with putting the "const" first is that it is ambiguous when there is more than one variable. For example, suppose that you want to open a file and test for errors: local f <close>, err = io.open("foo.txt") if not f then error(err) end vs local <close> f, err = io.open("foo.txt") if not f then error(err) end In the first version it is clearer that only the "f" variable is marked as a to-be-closed variable. The second version looks nicer when there is a single variable but is more confusing when there are multiple variables.
- Pxtl 6y agoEither way, why are the <> necessary? local f close = io.open("foo.txt") seems fine.
- ufo 6y agoThat wouldn't work because it is already valid Lua code with a different meaning. Lua parses it as a declaration of a local variable called f followed by an assignment to a variable named close: local f close = io.open("foo.txt") Despite the lack of semicolons, Lua is a free-form language and newlines are treated the same as any other whitespace character.