Luau Recap: October 2021

Luau is an extended version of lua. In fact, Roblox has used luau for some time already.

If you’ve learnt to code in lua there’s absolutely no difference other than some handy additions we didn’t get in the original lua. And those differences are way too small to call luau an entirely different language, or even engine.

4 Likes

You’re already using Luau if you write any code in roblox. Luau is meant to be easy to adopt if you know Lua and is completely backwards compatible.

3 Likes

You’re already using LuaU right now as you write your roblox code. I think you mean strict type checking instead, which likely won’t ever be forced; as it would break every existing game not using it.

2 Likes

@Gojinhan
@Optikk
@sthaple
thanks, phew. Imagine if it was a different coding program :slightly_frowning_face:

2 Likes

Yeah this is known, I believe we’re fixing this.

5 Likes

this works:

local isCool = false
local realResult = (isCool and 'isCool is true!!!') or 'isCool is not true'
print(realResult) -- < this returns 'isCool is not true'

i would LOVE if you could simply do:

local isCool = false
local realResult = isCool ? 'isCool is true!!!' : 'isCool is not true'
print(realResult) -- < returns 'isCool is not true'

hear me out… what if we also added this so it also works + has a good appearance

3 Likes

Unfortunately : cannot be used for this in Lua because it’s already used for method calls:

Consider: a = b ? c : d() : e()

Is that: a = b ? (c:d()) : e() or a = b ? c : (d():e())?

4 Likes

What about using ||?

Example:

local enabled = false
local example = enabled ? 'I am enabled.' || 'I am not enabled'

print(example) > returns 'I am not enabled'

( or if possible change “||” into “|”)

2 Likes

At that point there’s little value over something more readable using if / else (like what we chose) because it doesn’t match other languages anymore.

1 Like

I think that you have a good point, but Luau is already unique – why not add one thing that isn’t unique?

local result = if isCool then 'I am cool' else 'I am not cool'

can be shortened a good amount, into

local result = isCool ? 'I am Cool' || 'I am not cool'

It’s readable and although other languages use it, I think that it can be used in Luau as well to slightly reduce the developers’ time spent writing code.

We’ve already evaluated lots of different syntax options for this construct and chose if then else. Start using it - you’ll grow to like it.

6 Likes

Repost under the correct area:

Love the work! Are there any plans to add something akin to incrementing by 1 with both pre and post processing directives? An example to this would be ++numberValue(PreProcessing) and numberValue++(PostProcessing) This will help me out in sorting through numbers that I may not want to use in the current process that I’m trying to iterate through, allowing me to be a bit more flexible with how I design the methods I create.

2 Likes

I believe we’ve covered ++ before - we don’t have plans to add it. There’s many reasons as to why
not:

  • Pre- and post- forms are usually considered a mistake in language design, because the return value isn’t immediately obvious to readers unfamiliar with the arcane rules
  • Having an expression that modifies the variable results in complex order dependent evaluation and easy to make mistakes along the lines of process(foo++, foo) – this is also why our compound assignment operators are statements, not expressions
  • Adding a ++ without -- would leave a glaring symmetry gap in the language, but -- can not be added since it already means a comment
7 Likes

I guess that could make sense and honestly slipped over my head there. I come from a C++ background so it’s easy to get used to a certain way of codebase design. But love the work, the if-then-else is something that I instantly knew I’d start using. I’m a person who likes clean, minimal but effective code.

Now I won’t need to do

local value

if condition then value = value1 else value = value2 end

Makes those circumstances much more cleaner and I’m all for it :slight_smile:

1 Like

Curious as to why it wasn’t implemented exactly like Python. I think local a = b if c else d would make much more sense to read out loud, as well as the expression be shorter since there is no need for a then. But regardless, I’ll be using this.

1 Like

Still waiting until Luau’s typechecker supports t[k] on Roblox userdata types and not just table

1 Like

Wait, they just made the Roblox Studio scripting language more fast? Woah

1 Like

The order of evaluation is wrong and parsing it is problematic.

local a = print(1) if print(2) or true else print(3)
-- 2 gets printed first!

local b = print(1) if print(2) or true then print(3) end
-- this is actually 2 statements
local b = print(1)
if print(2) or true then print(3) end
-- figuring out if 'if' is an if statement or if expression is complex
-- with this syntax
3 Likes

Oh ma god. Finally found some lines that I understand lol.

1 Like

So are if-then-else and (x and y or) similar

1 Like