Module:File link: Difference between revisions

282 bytes added ,  10 years ago
move duplicate size error checks to the setting functions, fix the alignment error message
(fix read-only behaviour and remove the test function)
(move duplicate size error checks to the setting functions, fix the alignment error message)
Line 34: Line 34:
error('invalid format')
error('invalid format')
end
end
end
local function sizeError(methodName)
-- Used for formatting duplication errors in size-related methods.
error(string.format(
"duplicate size argument detected in '%s'"
.. " ('upright' cannot be used in conjunction with height or width)",
methodName
), 3)
end
end
Line 39: Line 48:
checkSelf(self, 'width')
checkSelf(self, 'width')
checkType('width', 1, px, 'number')
checkType('width', 1, px, 'number')
if data.isUpright then
sizeError('width')
end
data.theWidth = px
data.theWidth = px
end
end
Line 45: Line 57:
checkSelf(self, 'height')
checkSelf(self, 'height')
checkType('height', 1, px, 'number')
checkType('height', 1, px, 'number')
if data.isUpright then
sizeError('height')
end
data.theHeight = px
data.theHeight = px
end
end
Line 51: Line 66:
checkSelf(self, 'upright')
checkSelf(self, 'upright')
checkType('upright', 1, factor, 'number', true)
checkType('upright', 1, factor, 'number', true)
if data.theWidth or data.theHeight then
sizeError('upright')
end
data.isUpright = true
data.isUpright = true
data.uprightFactor = factor
data.uprightFactor = factor
Line 98: Line 116:
else
else
error(string.format(
error(string.format(
"bad argument #1 to 'alignment' ('%s' is not a valid alignment)"
"bad argument #1 to 'alignment' ('%s' is not a valid alignment)",
s
))
))
end
end
Line 155: Line 174:
-- Size
-- Size
if data.isUpright and (data.theWidth or data.theHeight) then
if data.isUpright and data.uprightFactor then
error("duplicate size value detected in 'render' (height/width cannot be used at the same time as 'upright')")
elseif data.isUpright and data.uprightFactor then
ret[#ret + 1] = 'upright=' .. tostring(data.uprightFactor)
ret[#ret + 1] = 'upright=' .. tostring(data.uprightFactor)
elseif data.isUpright then
elseif data.isUpright then