Content deleted Content added
add type checks and write the render function; read-only code not working yet |
fix read-only behaviour and remove the test function |
||
Line 14:
checkSelf(self, 'name')
checkType('name', 1, s, 'string')
end
Line 29:
}
if validFormats[s] then
else
error('invalid format')
Line 39:
checkSelf(self, 'width')
checkType('width', 1, px, 'number')
end
Line 45:
checkSelf(self, 'height')
checkType('height', 1, px, 'number')
end
Line 51:
checkSelf(self, 'upright')
checkType('upright', 1, factor, 'number', true)
end
Line 58:
checkSelf(self, 'resetSize')
for i, field in ipairs{'theWidth', 'theHeight', 'isUpright', 'uprightFactor'} do
end
end
Line 72:
}
if validLocations[s] then
else
error(string.format(
"bad argument #1 to '
s
))
Line 95:
}
if validAlignments[s] then
else
error(string.format(
"bad argument #1 to '
))
end
Line 105:
function data:border()
checkSelf(self, 'border')
end
Line 111:
checkSelf(self, 'link')
checkType('link', 1, s, 'string')
end
Line 117:
checkSelf(self, 'alt')
checkType('alt', 1, s, 'string')
end
Line 123:
checkSelf(self, 'caption')
checkType('caption', 1, s, 'string')
end
function data:render()
checkSelf(self, 'render')
local ret = {}
-- Image name.
if not
error('image:render: no image name was found')
end
ret[#ret + 1] = 'File:' ..
-- Image format
if
ret[#ret + 1] =
elseif
ret[#ret + 1] =
end
-- Border
if
ret[#ret + 1] = 'border'
end
-- Location
ret[#ret + 1] =
-- Alignment
ret[#ret + 1] =
-- Size
if
error("duplicate size value detected in 'render' (height/width cannot be used at the same time as 'upright')")
elseif
ret[#ret + 1] = 'upright=' .. tostring(
elseif
ret[#ret + 1] = 'upright'
elseif
ret[#ret + 1] = string.format('%dx%dpx',
elseif
ret[#ret + 1] = tostring(
elseif
ret[#ret + 1] = string.format('x%dpx',
end
-- Link
if
ret[#ret + 1] = 'link=' ..
end
-- Alt
if
ret[#ret + 1] = 'alt=' ..
end
-- Caption
ret[#ret + 1] =
return string.format('[[%s]]', table.concat(ret, '|'))
Line 225 ⟶ 224:
end
|