Book Image

Mastering the Nmap Scripting Engine

By : Paulino Calderon
Book Image

Mastering the Nmap Scripting Engine

By: Paulino Calderon

Overview of this book

Table of Contents (23 chapters)
Mastering the Nmap Scripting Engine
Credits
About the Author
Acknowledgments
About the Reviewers
www.PacktPub.com
Preface
Scan Phases
Script Categories
Nmap Options Mind Map
References
Index

Metatables and metamethods


Metamethods allow us to change the behavior of a table by writing custom functions for operators—such as comparing objects, arithmetical operations, and more. For example, let's say we would like to overload the "add" functionality of our table object with a new function that adds certain fields we select. Normally, the addition operation isn't valid on tables but, with metatables, we can overwrite the __add metamethod to perform whatever we need.

Arithmetic metamethods

The metamethods supported by Lua tables are as follows:

Metamethod

Description

__add

Addition operator

__mul

Multiplication operator

__sub

Subtraction operator

__div

Division operator

__unm

Negation operator

__pow

Exponentiation operator

__concat

Concatenation operator

Relational metamethods

The following relational metamethods are also supported by Lua tables:

Metamethod

Description

__eq

Equality

__lt

Less than

__le

Less than or equal to

The setmetatable function is used to set...