This is specific to vanilla Lua 5.3 but I want this on Roblox lua too, as lua checks does the index first exist in tables, is it possible to override this, so that metatables won’t check does the table in the index exist?
local mt = { };
function mt.__index(self, index)
if index == "oops" then
error("Oops!");
end;
end;
function new(val)
return setmetatable({ oops = 'oops'; value = val; }, mt);
end;
local a = new(2);
print(a.oops);
Like so it’ll return
instead of