Modul:File link: Unterschied zwischen den Versionen
reduce redundant error code
(seperate treatment of private fields and read-only fields, and add a __pairs metamethod) |
(reduce redundant error code) |
||
Zeile 247: | Zeile 247: | ||
for field in pairs(data) do | for field in pairs(data) do | ||
readOnlyFields[field] = true | readOnlyFields[field] = true | ||
end | |||
local function restrictedFieldError(key, restriction) | |||
error(string.format( | |||
"image object field '%s' is %s", | |||
tostring(key), | |||
restriction | |||
), 3) | |||
end | end | ||
Zeile 252: | Zeile 260: | ||
__index = function (t, key) | __index = function (t, key) | ||
if privateFields[key] then | if privateFields[key] then | ||
restrictedFieldError(key, 'private') | |||
else | else | ||
return data[key] | return data[key] | ||
Zeile 262: | Zeile 267: | ||
__newindex = function (t, key, value) | __newindex = function (t, key, value) | ||
if privateFields[key] then | if privateFields[key] then | ||
restrictedFieldError(key, 'private') | |||
elseif readOnlyFields[key] then | elseif readOnlyFields[key] then | ||
restrictedFieldError(key, 'read-only') | |||
else | else | ||
data[key] = value | data[key] = value |