Jump to content

Module:File link: Difference between revisions

6 bytes removed ,  10 years ago
reduce redundant error code
(seperate treatment of private fields and read-only fields, and add a __pairs metamethod)
(reduce redundant error code)
Line 247: Line 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
Line 252: Line 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]
Line 262: Line 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
Cookies help us deliver our services. By using our services, you agree to our use of cookies.