Module:File link: Difference between revisions
m
Undid revision 611451330 by Mr. Stradivarius (talk) whoops, that edit was supposed to be to the sandbox...
(allow specifying height and width values as strings ending in px) |
m (Undid revision 611451330 by Mr. Stradivarius (talk) whoops, that edit was supposed to be to the sandbox...) |
||
Line 5: | Line 5: | ||
local fileLink = {} | local fileLink = {} | ||
function fileLink.new(filename) | function fileLink.new(filename) | ||
Line 64: | Line 52: | ||
end | end | ||
local function | 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 | ||
function data:width(px) | function data:width(px) | ||
checkSelf(self, 'width') | checkSelf(self, 'width') | ||
checkType('fileLink:width', 1, px, 'number', true) | |||
px | if px and data.isUpright then | ||
sizeError('fileLink:width') | |||
end | |||
data.theWidth = px | data.theWidth = px | ||
return self | return self | ||
Line 107: | Line 73: | ||
function data:height(px) | function data:height(px) | ||
checkSelf(self, 'height') | checkSelf(self, 'height') | ||
checkType('fileLink:height', 1, px, 'number', true) | |||
px | if px and data.isUpright then | ||
sizeError('fileLink:height') | |||
end | |||
data.theHeight = px | data.theHeight = px | ||
return self | return self | ||
Line 217: | Line 185: | ||
data.theLang = s | data.theLang = s | ||
return self | return self | ||
end | |||
local function checkTypeStringOrNum(funcName, pos, arg) | |||
local argType = type(arg) | |||
if argType ~= 'nil' and argType ~= 'string' and argType ~= 'number' then | |||
error(string.format( | |||
"bad argument #%d to '%s' (string or number expected, got %s)", | |||
pos, | |||
funcName, | |||
argType | |||
), 3) | |||
end | |||
end | end | ||