Module:IP: Difference between revisions

From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
174 bytes removed ,  7 years ago
use getmetatable to implement isSubnetObject
(prevent leading zeroes in CIDR strings and add some comments)
(use getmetatable to implement isSubnetObject)
Line 496:
 
do
-- Metatable
local dataKey = {} -- A unique key for accessing Subnet objects' internal data.
local mt = {
__eq = function (self, obj)
return self:getCIDR() == obj:getCIDR()
end,
__tostring = function (self)
return self:getCIDR()
end,
}
 
-- Private static methods
local function isSubnetObject(val)
return typegetmetatable(val) == 'table' and val[dataKey] ~= nilmt
end
 
Line 508 ⟶ 516:
makeSubnetFromRaw = function (rawIP, bitLength)
-- Set up structure
local obj = setmetatable({}, mt)
local data = {
rawIP = rawIP,
Line 589 ⟶ 597:
end
 
return setmetatable(obj, {
__index = function (self, key)
if key == dataKey then
return data
end
end,
__eq = function (self, obj)
return self:getCIDR() == obj:getCIDR()
end,
__tostring = function (self)
return self:getCIDR()
end,
})
end
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu