Changes
m
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
checkTypeStringOrNumcheckType('fileLink:width', 1, px, 'number', true) if px = validateSizeand data.isUpright then sizeError('fileLink:width', px) end
checkTypeStringOrNumcheckType('fileLink:height', 1, px, 'number', true) if px = validateSizeand data.isUpright then sizeError('fileLink:height', px) end
Undid revision 611451330 by Mr. Stradivarius (talk) whoops, that edit was supposed to be to the sandbox...
local fileLink = {}
function fileLink.new(filename)
end
local function validateSizesizeError(method, pxmethodName) -- Validate input Used for formatting duplication errors in size-related functionsmethods. The px type is checked -- using checkTypeStringOrNum, so will be a string, a number, or nil. if px and data.isUpright then error(string.format( "duplicate size argument detected in '%s' " .. " ('upright' cannot be" .. ' used in conjunction with height or width)', method ), 3) end if type(px) == 'string' then local origPx = px px = px:match('^(%d+)px$') or px px = tonumber(px) if not px then error(string.format( "invalid string '%s' passed to '%s'", origPx, method ), 3) endmethodName end -- px is now a number or nil. if px and px < 1 or math.floor(px) ~= px then error(string.format( "invalid image size specified in '%s' (size must be a positive" .. 'integer)', method ), 3) end return px
end
function data:width(px)
checkSelf(self, 'width')
data.theWidth = px
return self
function data:height(px)
checkSelf(self, 'height')
data.theHeight = px
return self
data.theLang = s
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