mirror of
https://github.com/nmap/nmap.git
synced 2026-01-09 07:59:03 +00:00
Fix the documentation for nmap.new_try, because it was incorrect. The result of
nmap.new_try is not a function accepting another function, it is a function taking a variable number of arguments, assumed to be the return value of some function. In other words, the returned try function is not responsible for running other functions, it only sees their return values.
This commit is contained in:
@@ -1256,9 +1256,11 @@ end
|
||||
follows a functional programming paradigm rather than an
|
||||
object oriented programming paradigm. To create an exception
|
||||
handler the <literal>nmap.new_try()</literal> API method is
|
||||
used. This method returns a function, which takes a function
|
||||
as an argument. If the function passed as an argument raises
|
||||
an exception, then the script execution is aborted and no
|
||||
used. This method returns a function, which takes a variable
|
||||
number of arguments, assumed to be the return values of
|
||||
another function. If an exception is detected in the return
|
||||
values (the first return value is false),
|
||||
then the script execution is aborted and no
|
||||
output is produced. Optionally you can pass a function to
|
||||
the <literal>new_try()</literal> method which will be called
|
||||
if an exception is caught. In this function you can perform
|
||||
@@ -1309,7 +1311,8 @@ try(socket:send(result))
|
||||
construct consumes the indicator value and returns the
|
||||
remaining values. If the function failed then the second
|
||||
returned value must be a string describing the error
|
||||
condition. Note that if the value is not <literal>nil</literal> it is
|
||||
condition. Note that if the value is not
|
||||
<literal>nil</literal> or <literal>false</literal> it is
|
||||
treated as <literal>true</literal> so you can return your
|
||||
value in the normal case and return <literal>nil, <replaceable>error description</replaceable></literal>
|
||||
if an error occurs.
|
||||
|
||||
@@ -153,25 +153,24 @@ function nmap.mutex(object)
|
||||
|
||||
--- Creates a new exception handler.
|
||||
-- \n\n
|
||||
-- This function returns another function, which itself takes a function as an
|
||||
-- argument. When the returned function is called, it in turn calls the function
|
||||
-- passed to it as an argument, and checks the return value for an error. An
|
||||
-- error is signalled when the first return value of the function is false. If
|
||||
-- there is an error, the script will stop immediately and produce no output.
|
||||
-- And optional handler function can be called before the script is stopped. In
|
||||
-- this function you can perform any clean-up operations, such as closing
|
||||
-- sockets.
|
||||
-- This function returns another function, an exception handler. The returned
|
||||
-- function takes a variable number of arguments, which are assumed to be the
|
||||
-- return values of another function. It checks the return values for an
|
||||
-- exception, which is signalled when the first return value is false. If there
|
||||
-- is an exception, the script will stop immediately and produce no output. An
|
||||
-- optional handler function can be called before the script is stopped. In the
|
||||
-- error handler function you can perform any clean-up operations, such as
|
||||
-- closing a socket.
|
||||
-- @param handler Exception handler function (optional).
|
||||
-- @usage
|
||||
-- local result, socket, try, catch\n
|
||||
--\n
|
||||
-- \n
|
||||
-- result = ""\n
|
||||
-- socket = nmap.new_socket()\n
|
||||
-- catch = function() \n
|
||||
-- socket:close() \n
|
||||
-- catch = function()\n
|
||||
-- socket:close()\n
|
||||
-- end\n
|
||||
-- try = nmap.new_try(catch)\n
|
||||
--\n
|
||||
-- try(socket:connect(host.ip, port.number))\n
|
||||
-- result = try(socket:receive_lines(1))\n
|
||||
-- try(socket:send(result))
|
||||
|
||||
Reference in New Issue
Block a user