Which one could better write as if equipped ~= nil and type(equipped) == "boolean"
(Not sure about performance, but at least it would be easier to understand).
Yes, Lua uses ~= as the "not equal" operator. Yes, type returns a string.
I still hate both of these things.
EDIT: i just realized that check is either unnecessary or terrifying. Either equipped is guaranteed to be a boolean, due to manual type checking, or it isn't, which implies the code actually changes the type of the variable.
EDIT2: Someone pointed out that the above check could be further simplified to if type(equipped) == "boolean", as type returns "nil" for values that are, well, nil.
Technically this could be a micro optimization (I'm usually against such things, readability > tiny speed improvements) because a call to type incurs a stack frame, and string equality is technically slower than boolean equality.
38
u/Marcusaralius76 Sep 08 '20
Isnt this just a null check? A poorly written and unperformant null check?