Changes
fix read-only behaviour and remove the test function
checkSelf(self, 'name')
checkType('name', 1, s, 'string')
end
}
if validFormats[s] then
else
error('invalid format')
checkSelf(self, 'width')
checkType('width', 1, px, 'number')
end
checkSelf(self, 'height')
checkType('height', 1, px, 'number')
end
checkSelf(self, 'upright')
checkType('upright', 1, factor, 'number', true)
end
checkSelf(self, 'resetSize')
for i, field in ipairs{'theWidth', 'theHeight', 'isUpright', 'uprightFactor'} do
end
end
}
if validLocations[s] then
else
error(string.format(
"bad argument #1 to 'image:location' ('%s' is not a valid location)",
s
))
}
if validAlignments[s] then
else
error(string.format(
"bad argument #1 to 'image:alignment' ('%s' is not a valid alignment)"
))
end
function data:border()
checkSelf(self, 'border')
end
checkSelf(self, 'link')
checkType('link', 1, s, 'string')
end
checkSelf(self, 'alt')
checkType('alt', 1, s, 'string')
end
checkSelf(self, 'caption')
checkType('caption', 1, s, 'string')
end
function data:render()
checkSelf(self, 'render')
local ret = {}
-- Image name.
if not selfdata.theName then
error('image:render: no image name was found')
end
ret[#ret + 1] = 'File:' .. selfdata.theName
-- Image format
if selfdata.theFormat and selfdata.theFormatFilename then ret[#ret + 1] = selfdata.theFormat .. '=' .. selfdata.theFormatFilename elseif selfdata.theFormat then ret[#ret + 1] = selfdata.theFormat
end
-- Border
if selfdata.hasBorder then
ret[#ret + 1] = 'border'
end
-- Location
ret[#ret + 1] = selfdata.theLocation
-- Alignment
ret[#ret + 1] = selfdata.theAlignment
-- Size
if selfdata.isUpright and (selfdata.theWidth or selfdata.theHeight) then
error("duplicate size value detected in 'render' (height/width cannot be used at the same time as 'upright')")
elseif selfdata.isUpright and selfdata.uprightFactor then ret[#ret + 1] = 'upright=' .. tostring(selfdata.uprightFactor) elseif selfdata.isUpright then
ret[#ret + 1] = 'upright'
elseif selfdata.theWidth and selfdata.theHeight then ret[#ret + 1] = string.format('%dx%dpx', selfdata.theWidth, selfdata.theHeight) elseif selfdata.theWidth then ret[#ret + 1] = tostring(selfdata.theWidth) .. 'px' elseif selfdata.theHeight then ret[#ret + 1] = string.format('x%dpx', selfdata.theHeight)
end
-- Link
if selfdata.theLink then ret[#ret + 1] = 'link=' .. selfdata.theLink
end
-- Alt
if selfdata.theAlt then ret[#ret + 1] = 'alt=' .. selfdata.theAlt
end
-- Caption
ret[#ret + 1] = selfdata.theCaption
return string.format('[[%s]]', table.concat(ret, '|'))
end