Woah. O_O
There is only one word to describe something like this.
Dope.
I didn’t even know that anything like this was in the works! Also, if someone else is more familiar with typescript, please tell me he is making a custom class with this line right here?
The main issue with Lua is that it’s impossible for a compiler to know what the majority of your code will do before execution. This is why vanilla 5.1 only does some basic optimizations like simplifying maths, while LuaJIT only optimizes the code in specific instances. A major culprit of this are 100% type unsafe variables, since a parsed value can be a number or a boolean, a reference or a primitive. For example, if val then end will run if val is anything but false or nil.
but when are we getting compound operators?
its literally in every programming language besides lua, dont even mention that its supposed to be “simple” and not complex, because this post clearly shows that simplicity isnt really relevant anymore.
if you dont know what im talking about, it is operators like ++, --, +=, -=, *=, and /=.
code like this:
local a = 5
local b = 3
a = a + b
print(a)
can be shortened to this:
local a = 5
local b = 3
a += b
print(a)
it just gets more and more useful the longer the two values you are trying to add together are…
I don’t think I said that exactly. I don’t think we are going to ever add ++/— because of syntactic ambiguity. As for += et al - we don’t have this planned right now. Because of complexities with metatables if we ever add this, this would just make the code shorter, not faster. But maybe we will decide it’s worthwhile - ergonomics are important and we’re adding continue for this reason. If we ever add += et all these would be statements though unlike in C-derived languages.
I would think that you just dont reassign the variable? I dont use C# or C++ so I have no idea of any other advantages of using constant instead of just not updating the variable
The advantage is that you know for sure that the given variable never changes. In Javascript I often see the phrase “Reduce Immutable State” thrown around and so that is done by using the const keyword.
I’m getting a warning that I shouldn’t be getting:
local t = {}
do
local y = t
y.f = function(x)
return x + 1
end
end
local n = t.f(5)
It says: W000: (8,11) Key 'f' not found in table t
Of course this is a simplified example, but its giving me warnings over a large piece of code due to how I wrote it.
Is there any way that a type can be used across scripts? For example, I have one module that defines a type “Options”:
type Options = {
Delay: number
}
And then in another script I’m using this module and want to create a table specifying the options:
local options : Options = {
Delay = 5
}
But this causes an error because it doesn’t recognize the type “Options”. Other than having the type redefined, is there any other way to reuse the same type across different scripts?
Except you can’t effectively sandbox that stuff. The whole reason roblox uses lua cause it’s a sandbox language. They probably don’t want a snoopy developer poking about somebodies PC on their platform. That just screams legal issues.