Lua 5.4 has decided to move to 0-based indexes!

Haha. April fools. :) <3

Posted Apr 1, 2018, 5:30 PM UTC

9018
Saldor010•

I'll give an upvote since I thought it was legit for a few seconds :P

15
zeValkyrie•

Me too...

Although now that I think about it that's the mother of all ways to break backwards compatibility. Maybe build some automated migration scripts and try to adjust the index of tables everywhere? Fun fun... And what if I (for whatever terrible) reason already use arrays with keys of int 0? That is, although not advisable, completely possible. Should we just make those -1? Fuck whoever has to maintain that code :) This is gonna be super fun.

6
Saldor010•

Which is why no one in their right mind would make such a huge change to such a widely used language. Though to be fair, it does sound like a fun challenge to create a migration script like that.

3
zeValkyrie•

I'm not entirely sure it's even theoretically possible given that Lua keys are not inherently ints, they're just... anything. So depending on how the keys are added to the table they may now start at 0. Or not, they could just be int's from some external source (indexs of responses in a API call to something, for instance) so those shouldn't be shifted down by one.

Edit: this is making my head hurt

2
progfix•

They also add 'continue' and nested comment blocks! ^Haha^^no

9
fuxoft•

Lua already has nested comments, using --[[, --[=[, --[==[ etc...

5
coverslide•

You can also use --[==[====> to banish Ganon and save Hyrule

21
progfix•

Oh, I forgot about that.

1
DeathProgrammingOPsh &lt;(curl hashbang.sh)•

continue can actually be easily implemented using repeat until true. I'd post an example but I'm on my phone and lazy

2
lambda_abstraction•

Won't continue in full generality require goto and labels. (LuaJIT >= 2.0 or Lua >= 5.2) ?

1
DeathProgrammingOPsh &lt;(curl hashbang.sh)•
i = 0
while true do
  repeat -- continue guard
    i = i + 1
    if i % 2 == 0 then
      break -- continue
    end
    print(i)
  until true -- continue guard
end
-- this works on 5.1 :D
1
lambda_abstraction•

This isn't full generality. How do you break the while in this context without hacks like a flag var and second test? Break has already been co-opted by the nested "loop". When used judiciously (very rarely), goto can yield clearer code.

1
progfix•

I know that

0
casd82•

lol u got me

2