It’s clearly following in the footsteps of an Object-Oriented Programming language, I could assume the goal is to eventually make a class hierarchy (like polymorphism).
What’s the purpose of making Nonstrct stricter? I don’t see the purpose other than possibly making the scripts more optimized by giving more precise code.
Would you be able to have 2 functions of the same name, but take different types? Much like how C++ class methods work, then error if there is no function of that name with the correct type syntax?
This has a name; Overloading, and yes, i would it add but i think that it will be out with the Generics. I know this from Minecraft Modding (the reason why i am not very active in the community) and it exist in many Programming languages, like Java. I only want to know how we manually use it.
The conditional operator is more of a feature for “curly bracket” languages like C++, JavaScript, etc. Currently you can replicate this with a and b or c. However it messes up when b is falsey. "hi" ? false : true evaluates to false, but "hi" and false or true evaluates to true because of the nature of the and and or operators.
Btw a == a and true or false is redundant since the == operator always returns true or false
The reason why the spawn function warns like it does is because the annotation for the inside function has to return nil instead of nothing, which is redundant:
-- current correct way of using spawn:
spawn(function() => nil -- or `nil?`
print("stuff")
end)
Might have something to do with userdatas not being fully supported yet. The editor believes that tables are the only objects you can call methods on or set values to.
I also get a similar "Not a table: ImageButton|Texture|nil" error in my __newindex metamethod: self.Instance.Texture = v1
Hello, sorry for annoying you, but i still have a question: If we make a Function and we want to indicate a Parameters that was a Part, how to attempt this, @fun_enthusiast?
This was my idea:
local PartReference = Instance.new("Part")
local function Test(Part: PartReference)
--Does this work
end
--Else
local function OtherPossibility(Part: Instance)
--Or this was the best?
end
If i indicate that it was a Instance, it will sure work, but it not know that it was a Part. If here was a possibility to full indicate that it was a Part, how to attempt it or it was simply not possible?
It seems if you have strict mode on you can just do this:
--!strict
local Part = Instance.new("Part")
local Sound = Instance.new("Sound")
local function Test(part: Part)
end
Test(Sound) -- not ok
Test(Part) -- ok
Non-strict mode is for backwards compatibility so script without types still work. This is why a non-strict typed script does not error when you don’t pass in a Part. Strict mode makes it so it will error if the passed argument is not the right type. If you want to use types, I would suggest using strict mode.
It’s likely because functions do not necessarily return a single value. In this case it should know that setmetatable has a single result, but wrapping the final argument in parentheses should silence the warning:
setmetatable({}, (setmetatable({}, {})))
It’s inconvenient, but I recommend wrapping the final item in an array with parentheses if it’s a function call. This both improves performance, and prevents possible bugs if you decide your function should return more than one value later:
{foo(), foo()}
→
{foo(), (foo())}
You may also do this for returns or function call arguments, but the performance impact isn’t as significant.
Actually, are there cases where providing the results of a call like this can cause deoptimizations @zuexcg?
For example, how does this:
for i, v in ipairs(foo()) do
end
local bar = math.abs(foo())
compare to this:
for i, v in ipairs((foo())) do
end
local bar = math.abs((foo()))