3 ms·
the point is that lua didn't make the mistake of false 'empty' values, so that particular sharp edge is absent
by smegsicle 3y ago
the point is that lua didn't make the mistake of false 'empty' values, so that particular sharp edge is absent
- DemocracyFTW2 3y agoThe edge of "false 'empty' values" is absent in Lua, indeed, but the `a = b or c`, more often used in the form `b = b or c`, has, in Lua, still the problem that it will evaluate to `c` if `b` is `nil` and when b is `false` which may or may not be what one wants—and often one wants it not. The idiom is commonly used to assign a proper value to a variable that has not been set to an explicit value, i.e. a variable that is `nil`. The assignment `b = b or true` will set `b` to `true` if it was `nil` or `false`; assuming allowable values for `b` are `true` and `false` and the default is `true`, `b` will then never keep the value of `false` and always be set to `true`.