Anonymous user
Module:IP: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
allow creation of IPAddress objects from their parts with newIPFromParts
(don't need to fall through to IPAddress in __index if the methods are inside the constructor) |
(allow creation of IPAddress objects from their parts with newIPFromParts) |
||
Line 171:
local IPAddress = {}
-- newIPFromParts constructs a new IPAddress object from its parts. It needs to
-- be accessible from the Subnet object but it should not be public.
local newIPFromParts
do
Line 278 ⟶ 282:
end
--
newIPFromParts = function
-- Constructs a new IPAddress object from its parts. This function is
checkType('IPAddress.new', 1, ip, 'string')▼
-- for internal use; it is called by IPAddress.new and can be called
-- from the Subnet class, but it is not available to other modules.
assert(type(parts) == 'table', 'parts was type ' .. type(parts) .. '; expected type table')
-- Set up structure
local obj = {}
local data = {
parts = parts,
}
data.parts = parseIPv4(ip) or parseIPv6(ip)▼
if not data.parts then▼
error('invalid IP', 2)▼
end▼
▲ data.version = data.parts.n == 2 and V4 or V6
-- Public methods
Line 303 ⟶ 306:
function obj:getHighestIP(bitLength)
return
end
function obj:getPrefix(bitLength)
return
end
Line 329 ⟶ 332:
function obj:getNextIP()
return
end
function obj:getPreviousIP()
return
end
Line 348 ⟶ 351:
end,
})
end
function IPAddress.new(ip)
▲ checkType('IPAddress.new', 1, ip, 'string')
▲ error('invalid IP', 2)
▲ end
return newIPFromParts(parts)
end
end
|