Nmap Development mailing list archives

Re: [Lua snippit] print_hex


From: "Patrick Donnelly" <batrick.donnelly () gmail com>
Date: Sun, 7 Sep 2008 22:47:18 -0600

On Sun, Sep 7, 2008 at 9:51 PM, Ron <ron () skullsecurity net> wrote:
I agree that a best practices or style guide of some kind would be
handy. While writing a script, there were a few times when I wasn't sure
what the proper style was. Here are some thoughts I had while I was writing:
- Tab indenting or spaces? If spaces, how many?
- Should there be a maximum line length?

These two are very open to personal style. I use only spaces (2 for
each indent) and restrict myself to 80 characters per line (so they
fit in a standard terminal window).

- Is it better to use, for example, str:len() or string.length(str)?

Each data type in Lua can have a metatable (some can have individual
metatables like tables and full userdata). The string metatable
indexes the global string library. This usually involves 2 table
indexes (one for __index and one for "len"). The second (which should
be string.len) is also two table indexes (one for string global,
second for indexing "len"). I usually use the first because it is
shorter and is two table indexes regardless of where you call it from
(for instance, you could be in a module where it would be three
indexes). If you have the string library (or the len function) local,
then string.len will always be faster than the metatable access.

Thankfully, Lua doesn't have braces so I don't have to be upset at
people who put their braces in the clearly wrong place (you know where
they ought to be)! :)

Table constructors have braces :P

Cheers,

-- 
-Patrick Donnelly

"One of the lessons of history is that nothing is often a good thing
to do and always a clever thing to say."

-Will Durant

_______________________________________________
Sent through the nmap-dev mailing list
http://cgi.insecure.org/mailman/listinfo/nmap-dev
Archived at http://SecLists.Org


Current thread: