2 ms·
Ehh, local being a keyword (instead of local default, global only if required) was a significantly bigger gaff. The other would be no nulls in tables. 0/1 based
by fbdab103 3y ago
Ehh, local being a keyword (instead of local default, global only if required) was a significantly bigger gaff. The other would be no nulls in tables. 0/1 based indexing is familiarity only.
- josephcsible 3y agoRequiring a keyword to declare a variable is a good thing. Otherwise, it'd be easily to accidentally declare new variables when you meant to assign to an existing one. Since global is the default, starting a program with something like this effectively keeps that from happening: local gindex = {} setmetatable(_G, {__index = function(t,k) local v = gindex[k] if v == nil then error("Bad read of global variable " .. tostring(k), 2) else return v end end, __newindex = function(t,k,v) error("Bad write of global variable " .. tostring(k), 2) end}) for k,v in pairs(_G) do gindex[k] = v rawset(_G, k, nil) end