Anonymous user
Module:IP: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
use libraryUtil for the checkSelf function
(prevent access to IPAddress metatables, and add some more comments) |
(use libraryUtil for the checkSelf function) |
||
Line 8:
local checkType = libraryUtil.checkType
local checkTypeMulti = libraryUtil.checkTypeMulti
local makeCheckSelfFunction = libraryUtil.makeCheckSelfFunction
-- Constants
Line 17 ⟶ 18:
--------------------------------------------------------------------------------
local function
-- Makes a function for classes to check that their methods have a valid▼
-- self parameter.▼
-- Make a function for validating a specific object.
return function (methodName, argIdx, arg)
Line 368 ⟶ 356:
end
local checkSelf = makeCheckSelfFunc(▼
'IPAddress',▼
'ipAddress',▼
▲ validateIPAddress = makeValidationFunc('IPAddress', isIPAddressObject)
-- Metamethods that don't need upvalues
Line 407 ⟶ 387:
local data = {}
data.rawIP = rawIP
▲
'IP',
▲ 'ipAddress',
obj,
)
-- Public methods
function obj:getIP()
checkSelf(self, 'getIP'
return tostring(data.rawIP)
end
function obj:getVersion()
checkSelf(self, 'getVersion'
return data.rawIP:getVersion()
end
function obj:isIPv4()
checkSelf(self, 'isIPv4'
return data.rawIP:isIPv4()
end
function obj:isIPv6()
checkSelf(self, 'isIPv6'
return data.rawIP:isIPv6()
end
function obj:isInSubnet(subnet)
checkSelf(self, 'isInSubnet'
local tp = type(subnet)
if tp == 'string' then
Line 443 ⟶ 432:
function obj:getSubnet(bitLength)
checkSelf(self, 'getSubnet'
checkType('getSubnet', 1, bitLength, 'number')
return makeSubnetFromRaw(data.rawIP, bitLength)
Line 449 ⟶ 438:
function obj:getNextIP()
checkSelf(self, 'getNextIP'
return makeIPAddressFromRaw(data.rawIP:getAdjacent())
end
function obj:getPreviousIP()
checkSelf(self, 'getPreviousIP'
return makeIPAddressFromRaw(data.rawIP:getAdjacent(true))
end
Line 523 ⟶ 512:
-- argIdx (number) - the position of the argument in the argument list
-- arg - the argument to be validated
validateSubnet =
-- Constructors
|