Why does _VERSION return "Luau" instead of "Lua 5.1" and why does += operator suddenly work?

Viewed 293

I found out the _VERSION returns "Luau" instead of "Lua 5.1". I also found out continue and the += operator works

print(_VERSION) -- Luau
value = 0
value += 1
print(value) -- Doesn't return a syntax error
for k, v in ipairs({1, 2, 3, 4}) do
  if k == 1 then
    continue -- This works?
  end
  print(v)
end

prints

1
2
3
4

I also messed around with it and realized type annotation works.

function foo(x: number, y: string): boolean
    local k: string = y:rep(x)
    return k == "a"
end

doesn't throw a syntax error. I also found out table.find, table.create and math.clamp is removed in Lua 5.4 as well as typeof function

I also realized binary literal print(0b10) returns 2 in Lua 5.1 but throws an error in Lua 5.4, along with print(1_000) which returns 1000 in Lua 5.1, but doesn't work in Lua 5.4

Why does these suddenly work on Lua 5.1? Did not expect it to work Lua 5.1 When I switched to Lua 5.4, _VERSION returns "Lua 5.4" instead and continue doesn't work and typeof was removed (How do I check types in Lua 5.4?). What's going on? And why does Lua 5.4 remove the += , continue operator and why does _VERSION return Luau in Lua 5.1?

1 Answers

Simple as: it's not Lua 5.1.

It's Luau, a language derived from Lua 5.1 and backwards-compatible with it. That's why your usual 5.1 code works and why you can use other funky stuff. It's currently closed source and under development by Roblox.

As for Lua 5.4, see its Reference Manual to know what to expect from it.

Related