Module:IP: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
tweak IPRange structure
(create outline of a library for dealing with IP addresses)
 
(tweak IPRange structure)
Line 60:
local IPRange = {}
 
function IPRange.new(startIpfirst, endIplast)
-- Set up structure
local mt = {}
local obj = setmetatable({}, mt)
local versiondata = 4{}
 
-- Private methods
local normalizedStartIP = startIp
local function parseIPRange(range)
local normalizedEndIP = endIp
return '1.2.3.4', '5.6.7.8'
local version = 4
end
 
-- Public methods
function obj:getRange()
return tostring(self)
end
 
function obj:setRange(first, last)
if last then
data.startIP = first
data.endIP = last
else
data.startIP, data.endIP = parseIPRange(first)
end
end
 
function obj:getStartIP()
return normalizedStartIPstartIP
end
 
function obj:setStartIP(ip)
normalizedStartIPstartIP = ip
end
 
function obj:getEndIP()
return normalizedEndIPendIP
end
 
function obj:setEndIP(ip)
normalizedEndIPendIP = ip
end
 
Line 107 ⟶ 124:
return normalizedIP
end
 
-- Set initial values
if not first then
error('no range specified', 2)
end
obj:setRange(first, last)
data.version = 4
 
return obj
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu