Module:IP/doc: Difference between revisions

Content deleted Content added
m change source to syntaxhighlight
Add descriptions on error handling
Line 26:
local ipv4Address = IPAddress.new('1.2.3.4')
local ipv6Address = IPAddress.new('2001:db8::ff00:12:3456')
</syntaxhighlight>
 
If a non-IP string or an invalid IP address is passed to the function, that returns an error. If you want to check whether a given string is an IP address and continue the procedure in the caller module, use [[:mw:Extension:Scribunto/Lua_reference_manual#pcall|pcall]].
 
<syntaxhighlight lang="lua">
local isIp, ip = pcall(IPAddress.new, '1.2.3.4') -- isIp: true, ip: IPAddress object
local isIp, ip = pcall(IPAddress.new, 'Example') -- isIp: false, ip: nil
local isIp, ip = pcall(IPAddress.new, '1.2.3.256') -- isIp: false, ip: nil
</syntaxhighlight>
 
Line 194 ⟶ 202:
 
<var>cidrString</var> must be a valid IPv4 or IPv6 [[CIDR]] string.
 
<syntaxhighlight lang="lua">
local cidr = Subnet.new('255.255.255.0/24') -- Subnet object
local cidr = Subnet.new('255.255.255.1/24') -- error
</syntaxhighlight>
 
Subnet objects can be compared for equality: