Anonymous user
Module:IP: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
mt can still be defined outside the constructor, though - it can just return true for uniqueKey instead of an upvalue
(need to use __index to have a unique key which is really private - if outside code gets uniqueKey with getmetatable then they can set it in another table's __eq metamethod, thus foiling isSubnetObject) |
(mt can still be defined outside the constructor, though - it can just return true for uniqueKey instead of an upvalue) |
||
Line 489:
-- is a Subnet object.
local uniqueKey = setmetatable({}, {__metatable = false})
-- Metatable
local mt = {
__eq = function (self, obj)
__concat = function (self, obj)
}
-- Private static methods
local function isSubnetObject(val)
-- Return true if val is a Subnet object, and false otherwise.
return
end
Line 502 ⟶ 521:
-- arg - the argument to be validated
validateSubnet = makeValidationFunction('Subnet', isSubnetObject)
▲ return subnet1:getCIDR() == subnet2:getCIDR()
▲ end
▲ return tostring(subnet1) .. tostring(subnet2)
▲ end
▲ return subnet:getCIDR()
▲ end
-- Constructors
makeSubnetFromRaw = function (rawIP, bitLength)
-- Set up structure
local obj = setmetatable({}, mt)
local data = {
rawIP = rawIP,
Line 635 ⟶ 641:
end
return
▲ __index = function (self, key)
▲ if key == uniqueKey then
▲ return true
▲ end
▲ end,
▲ __tostring = subnetToString,
▲ __metatable = false,
end
|