Zum Inhalt springen

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
error(string.format(
restrictedFieldError(key, 'private')
"image object field '%s' is private",
tostring(key)
), 2)
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
error(string.format(
restrictedFieldError(key, 'private')
"image object field '%s' is private",
tostring(key)
), 2)
elseif readOnlyFields[key] then
elseif readOnlyFields[key] then
error(string.format(
restrictedFieldError(key, 'read-only')
"image object field '%s' is read-only",
tostring(key)
), 2)
else
else
data[key] = value
data[key] = value
Anonymer Benutzer