Top
Best
New

Posted by phreddypharkus 15 hours ago

LuaJIT 3.0 proposed syntax extensions(github.com)
201 points | 119 comments
Ardren 12 hours ago|
> For compatibility with other computer languages, the following classic Lua operators can be written in a more customary syntax:

Why though? What does changing `and` to `&&` actually achieve? Were people confused?

Changing the syntax seems very surface level. It's not actually fixing any problems, just making Lua no longer look like Lua. It's not going to help anyone write/learn Lua. It will make everything more complicated as there are now two ways to do everything.

This feels like adding braces to Python because you don't like indenting your code.

nullpoint420 10 hours ago||
> This feels like adding braces to Python because you don't like indenting your code.

Now this I can get behind...

bonoboTP 6 hours ago||
You need Bython https://github.com/mathialo/bython
simonask 8 hours ago|||
Ruby has both kinds of operators as well, and it's fine. The thing in Ruby, though, is that the English logical operators have lower precedence than the symbolic logical operators, so you can use them in place of parentheses. Sometimes that's confusing, other times it can be used to make code very readable.

In general, I would expect symbolic operators to be desirable in complex boolean expressions, because "loud punctuation" stands out among English words when reading the code.

spider-mario 6 hours ago|||
Same in Perl, hence the good old pattern:

    open my $fh, '<', 'input.txt' or die;
codesnik 5 hours ago||
yes, ruby inherited this from perl, though 'or' has lower precedence than 'and' in perl, and they're equal in ruby. Which sounds like something going to cause mistakes, but I yet to see 'and' and 'or' together in the same expression in ruby.
ClikeX 4 hours ago|||
I've always found it odd that and/or in Ruby isn't just considered equal to &&/||, and I have never really used the english operators except for the usual modifiers like if and unless.

What is a practical use case where the lower precedence makes sense?

aeonflux 1 hour ago||
Those two behave in the same way if you drop the parentheses:

1. statement if (condition || something)

2. (statement if condition) or something

doophus 9 hours ago||
> Why though? What does changing `and` to `&&` actually achieve? Were people confused?

Also consider AI, that has a greater training base of JavaScript than Lua. So making Lua look more like JS, should improve output and reduce mistakes.

boomlinde 26 minutes ago|||
I can't imagine that making the differences between the languages more subtle would improve the performance of chatbots. Subtleties aren't their strong suit.
lionkor 8 hours ago||||
No, don't consider AI.
boxed 8 hours ago||||
AI has greater training on Python, which uses `and` and `or`, and it has absolutely no issue keeping that straight.
Heliodex 14 hours ago||
A comment <https://github.com/LuaJIT/LuaJIT/issues/1475#issuecomment-47...> has already been made on the issue regarding the ternary operator, recommending `if x then y else z` over `x ? y : z`. This is exactly how it's done with if-then-else expressions in Luau <https://luau.org/syntax/#if-then-else-expressions>, another language compatible with Lua, and makes it a ton easier to nest (especially with elseif) and I believe still easier to read than `y if x else z`.
drunken_thor 41 minutes ago||
I think that allowing an if statement to return a value to deal with the ternary introduces a now concept to Lua and that is that the value on the final line of a block is a return value much like Ruby. This changes the logic of the entire language more than adding a ternary. I do prefer the if statement as it allows so much more emergent behaviour, but it does have more implications to consider.
noelwelsh 8 hours ago|||
Exactly. I don't understand why people think the ternary operator is needed when you can just make `if` an expression instead of a statement. Then there is no new syntax to learn and `if` just becomes more useful.
aeonflux 1 hour ago||
I don't really understand where is this need to compress the logic into where small chunks comes from. In result we get single line of code which has multiple statement conditions, different paths, and it's not possible to grasp in one go.

Other practical example why ternary is bad: Many code-coverage solutions break on ternary because they don't correctly see that one of the branches was missed in tests.

mjcohen 13 hours ago||
The ternary operator is easy to nest if you put each clause on a separate line. Then it looks just like nested if-then-else.
edoceo 13 hours ago|||
I love the ternary operator as much as anyone. But dang if it doesn't get hard to read when there is are a few, nested even.

Does that operator compile to faster assembly that if I make the same logic with verbose `if` logic? Is that a language specific outcome?

gnubison 12 hours ago||

    cond1 ? res1 :
    cond2 ? res2 :
    cond3 ? res3 :
    or_else_res
If they are truly nested, then that is confusing. But if you have an if-else chain, then it can be quite readable.
a-french-anon 7 hours ago|||
Or they could just ask granddaddy for advice:

  (cond (cond1 res1)
        (cond2 res2)
        (cond3 res3)
        (t     else_res))
=)
froh 2 hours ago||||
or

  if cond1 then res1
  else if cond2 then res2
  else if cond3 then res3
  else or_else_res
or

  if cond1 then res1
  elif cond2 then res2
  elif cond3 then res3
  else or_else_res
what is most lua-like?
shevy-java 12 hours ago|||
I find that so much harder to read compared to if/else or case/when in ruby.

The ? is basically an attempt to use fewer if/else, at the cost of condensed if-else like structure. I always need to look at both parts after the ? whereas in a single if or elsif I don't. case/when in ruby is even better here e. g. regex check:

   def foo(i)
     case i
     when /^cat/
       handle_cats
     when /^dog/
       handle_dogs
(I ommitted the "end"s here to just focus on the conditional logic.)
spider-mario 6 hours ago|||
Unless you mess up its associativity, like PHP until 7.4.

https://wiki.php.net/rfc/ternary_associativity

http://phpsadness.com/sad/30

mid-kid 2 hours ago||
LuaJIT has held back the lua ecosystem for over a decade. There's no reason to not at least try to move the implementation closer to luau or puc lua, not create yet more incompatible syntax
kzrdude 2 hours ago|
I don't think Lua is your average ecosystem. Lua is used as an embedded interpreter. For example, Neovim doesn't want to change its configuration language's syntax just because there is a new version of Lua available.

On the contrary, we can claim that luajit has stabilized lua for implementations and for users (strengthening Lua 5.1 dominance, which makes the experience more homogenous across apps).

pansa2 14 hours ago||
So is LuaJIT resuming active development after a decade or so of only maintenance? Great!

A lot of these changes make sense (although some of them are a bit too TIMTOWTDI for my taste) - but perhaps LuaJIT 3 would benefit from a change of name as well? Certainly with all these changes, it would be more like a separate language than merely a JIT-compiled version of Lua.

orthoxerox 8 hours ago||
A bunch of them are from Luau, the Roblox fork of Lua and the dialect most young programmers know. Adding them to LuaJIT will make it easier to write for both Zoomers and AI agents, who have been exposed to a lot of Luau code.
krapp 5 hours ago||
I know the LuaJIT maintainer(s?) will never add it because it's too radical a departure from Lua but I wish they would include Luau's type annotations. There are typed languages like Teal that will compile to Lua that should work (although I've had a difficult time getting Teal to work with cdefs) and you can kind of fake it by using C structs obviously but having such a feature be native to Lua itself would be nice.
201984 14 hours ago||
>TIMTOWTDI

What on earth is this supposed to mean?

Twirrim 14 hours ago|||
There Is More Than One Way To Do It.

That takes me back a bit. It's a perl-ism. I used to think it was a great design feature but I've come to strongly prefer "There should be one way to do it, and it should be obvious"

BobBagwill 1 hour ago|||
TCBOO, AKA, the Highlander Conjecture.
201984 14 hours ago||||
Interesting, thank you.
ncruces 6 hours ago|||
Using acronyms is one of those ways. /s
matheusmoreira 14 hours ago||||
There is more than one way to do it.
omoikane 12 hours ago||
Lua 5.3 (2015-01-12) added the bitwise operators:

https://www.lua.org/versions.html#5.3

https://www.lua.org/manual/5.3/manual.html#3.4.2

Looks like LuaJIT is catching up, but calling these "syntax extensions" is confusing. Is the intent to hold LuaJIT fixed against some earlier Lua version (I guess 5.1) and adopt newer syntax piecemeal?

I welcome the compound assignment operators. Playdate's version of Lua also has that extension.

orthoxerox 8 hours ago|
LuaJIT is an involuntary fork of 5.1. It already had various extensions that conflicted with the 5.2 implementation of the same features, and Mike Pall made it clear on the mailing list he wasn't going to change how LuaJIT worked.
coneonthefloor 53 minutes ago||
The syntax proposals look fine. But I don’t feel they are needed. Lua is easy to write and grok. I default to using LuaJIT, and have never had an issue with the actual code. Integration with the Lua ecosystem is the problem. Fix the compatibility issues with LuaRocks packages and PucRio. That would be the best dev ex update in my opinion.
lt-runtime 9 minutes ago||
The question is does the coding agent like it or not ?
camgunz 9 hours ago||
One of the interesting things about Lua is because they don't really maintain compatibility between major versions, there isn't a huge ecosystem, and as a result there's less friction against making your own, slightly incompatible version. When you add on the simplicity of implementing the language, it's created a really diverse set of lua-alikes. Weird (and cool) for a language to have a diverse ecosystem of implementations, but not necessarily libraries.
ianm218 13 hours ago||
Tangently related but I’ve been deep in Lua recently working on a rust implementation that supports Lua 5.1-5.5 in one Rust Binary https://github.com/ianm199/omnilua.

My ultimate goal was to support LuaJIT in Rust as well but this does not make it easier.

valorzard 9 hours ago||
Also, one issue I have with this repo is that, since so much of it seems to use Claude, as an actual human I struggle to read and parse any of the information.

For example, what’s the performance like?

ianm218 2 hours ago||
Performance dashboard is linked here https://ianm199.github.io/omnilua/performance.html.

In a mix of official and unofficial benchmarks wall clock performance is ~1.4x as fast as C Lua and the memory usage is ~1.7x.

So performance is worse to be clear but within range. There’s some performance improvements I haven’t gone for yet that would get it down to ~1.1 I think.

lifthrasiir 10 hours ago|||
Oh wow, seriously, I always thought Lua should have been like this. The 5.1/5.2/5.3+ split was so painful.

> My ultimate goal was to support LuaJIT in Rust as well but this does not make it easier.

I think you could stop right before the syntax extension.

genxy 11 hours ago|||
This is amazing! Can a program call across versions? Like could we take a Lua 5.1 codebase and upgrade only a portion of it at a time to a new Lua version?
ianm218 18 minutes ago||
Hmm I think in general I would not recommend doing this just because Lua does change pretty significant things from 5.1-5.5 so you could have some really hard to understand behavior if some portions are 5.1 vs 5.4 for example.

I think where it would be most helpful is converting a codebase and being able to easily run tests to ensure behavior is the same.

I created a github gist https://gist.github.com/ianm199/5ba0366376eca673142e1f0c79b4... that explains what is practical (I used AI for this to be clear feel free to skim).

Do you have a use case in mind? Would love to chat or take a look at an github issue if you create one.

valorzard 9 hours ago||
[dead]
ricardobeat 14 hours ago|
I see JavaScript.

Some of these really look like QoL improvements. I'm not convinced ternary statements are an ergonomic improvement in particular. The examples given don't make a compelling case, 'visually tidy' is not the same as readable.

nine_k 13 hours ago||
Worse, I see C (as in ! or &&), and Perl (as in manifestly more than one way to do it).

There are real improvements though, such as ?. and ??= that help with default-nullable everything.

Ternary is very useful, but it I'd rather see it implemented idiomatically:

  pos += (if forward then +1 else -1)
Structural pattern-matching could be fantastic, but no syntax is suggested.
jsomedon 6 hours ago|||
I kinda have seen somewhere on internet, that the language design of lua and js(well, ecmascript to be precise) is somehow related. But can't really find the exact reference I have seen.. it was long time ago when I read this.
cygx 4 hours ago||
There's some overlap in the languages they were inspired by (eg Scheme, or the chains Modula -> Lua vs Modula -> Java -> Javascript), but as far as I'm aware, the original designs were made independently.

Now, the object systems do look similar, but that seems to be a case of convergent evolution: Javascript took direct inspiration from Self, whereas Lua's system is based on a more generic fallback mechanism for table access.

fluoridation 8 hours ago||
Lua to me always felt very JavaScripty, just with a different syntax.
drdexebtjl 2 hours ago||
Lua predates JavaScript by about 2 years though.
More comments...