Anonymous user
Module:IP: Difference between revisions
From the Croc Wiki, the Croc encyclopedia
Jump to navigationJump to search
don't allow setting a new IP address in IPAddress objects - this doesn't make much sense
(fix metatable error) |
(don't allow setting a new IP address in IPAddress objects - this doesn't make much sense) |
||
Line 4:
-- Load modules
local libraryUtil = require('libraryUtil')
local checkType = libraryUtil.checkType
-- Constants
Line 22 ⟶ 23:
-- Constructor
function IPAddress.new(ip)
checkType('IPAddress.new', 1, ip, 'string')
-- Set up structure
local obj = setmetatable({}, mt)
local data = {}
end▼
-- Public methods
function obj:getIP()
return data.ip
data.ip = ip▼
if ip:find('^%x?%x?%x?%x?:') then▼
data.version = V6▼
elseif ip:find('^%d') then▼
else▼
error('invalid IP', 2)▼
end
Line 69 ⟶ 51:
-- Set initial values
▲ end
return obj
|