Home page logo
/

nmap-dev logo Nmap Development mailing list archives

Re: Variable number of arguments functions - arg not declared
From: Patrick Donnelly <batrick () batbytes com>
Date: Mon, 28 May 2012 13:45:21 -0400

On Mon, May 28, 2012 at 12:49 PM, Aleksandar Nikolic
<nikolic.alek () gmail com> wrote:
Hi all,


I've merged the changes from trunk to my exp branch
to change the scripts I'm working on to suit new lua updates.

I've had a problem with variable number of arguments functions
in rmi.lua library.

As far as I can tell, "arg" variable is deprecated in new version.

For example:

local function dbg(str,...)
       stdnse.print_debug(3,"RMI:"..str, table.unpack(arg))
end

Would throw an error saying arg was not declared.
I changed that to:

local function dbg(str,...)
       local arg={...}
       stdnse.print_debug(3,"RMI:"..str, table.unpack(arg))
end

Am I doing something wrong?
I'm bringing this to your attention as it might not be the only place
arg is used.

arg was a feature of Lua 5.0. Lua 5.1 provided compatibility support
for it which was removed in 5.2.

When dealing with varargs, you usually use these Lua functions:

http://www.lua.org/manual/5.2/manual.html#pdf-table.pack
http://www.lua.org/manual/5.2/manual.html#pdf-table.unpack
http://www.lua.org/manual/5.2/manual.html#pdf-select

Keep in mind you can treat the vararg as a regular expression (list).
In particular, this code:

local function dbg(str,...)
       local arg={...}
       stdnse.print_debug(3,"RMI:"..str, table.unpack(arg))
end

can be simplified as

local function dbg(str,...)
       stdnse.print_debug(3,"RMI:"..str, ...)
end

This subject is talked about in the manual [1] but it is very terse.
If you have questions on this, feel free to email me about it.

[1] http://www.lua.org/manual/5.2/manual.html#3.4.10
-- 
- Patrick Donnelly
_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://seclists.org/nmap-dev/

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]
AlienVault