Modul:File link: Unterschied zwischen den Versionen
K
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) |
K (Undid revision 611451330 by Mr. Stradivarius (talk) whoops, that edit was supposed to be to the sandbox...) |
||
Zeile 5: | Zeile 5: | ||
local fileLink = {} | local fileLink = {} | ||
function fileLink.new(filename) | function fileLink.new(filename) | ||
Zeile 64: | Zeile 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 | ||
Zeile 107: | Zeile 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 | ||
Zeile 217: | Zeile 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 | ||