Anonymous user
Module:IP: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
add IPAddress __concat; minor style changes
(use some functions from Module:IPblock to start implementation) |
(add IPAddress __concat; minor style changes) |
||
Line 11:
--------------------------------------------------------------------------------
-- TODO Remove items from these notes when satisfied they are ok.
-- IPAddress does not need mt:__le(obj) as Lua evaluates (a <= b) as (not (b < a))
Line 25:
-- which might be different from the input. Example:
-- input "1:02:003:0004:0:0:0:0" is "1:2:3:4::" after normalization.
-- Should obj:getIPParts() be removed?
-- Instead, move the metamethods into IPAddress.new(ip) so they can
-- access the data upvalue?
------------------------------------------------------------------------
Line 54 ⟶ 58:
end
local function
-- Return a string equivalent to the given IPv6 address.
local z1, z2 -- indices of run of zeros to be displayed as "::"
Line 98 ⟶ 102:
end
local function
-- Return a string equivalent to given IP address (IPv4 or IPv6).
if ip.n == 2 then
Line 111 ⟶ 115:
return table.concat(parts, '.')
end
return
end
local function
-- If
-- return true. Otherwise, return false.
-- This representation is for compatibility with IPv6 addresses.
local octets = collection()
local s =
for item in s:gmatch('(.-)%.') do
octets:add(item)
Line 149 ⟶ 153:
end
local function
-- If
-- return true. Otherwise, return false.
local _, n =
if n < 7 then
end
local parts = collection()
for item in (
parts:add(item)
end
Line 245 ⟶ 249:
-- Metamethods
function mt:__concat(obj)
return tostring(self) .. tostring(obj)
end
function mt:__eq(obj)
local lhs, rhs = self:getIPParts(), obj:getIPParts()
Line 272 ⟶ 280:
function mt:__tostring()
return
end
end
|