-
Book Overview & Buying
-
Table Of Contents
Mastering the Nmap Scripting Engine
By :
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.
The metamethods supported by Lua tables are as follows:
|
Metamethod |
Description |
|---|---|
|
|
Addition operator |
|
|
Multiplication operator |
|
|
Subtraction operator |
|
|
Division operator |
|
|
Negation operator |
|
|
Exponentiation operator |
|
|
Concatenation operator |
The following relational metamethods are also supported by Lua tables:
|
Metamethod |
Description |
|---|---|
|
|
Equality |
|
|
Less than |
|
|
Less than or equal to |
The setmetatable function is used to set...
Change the font size
Change margin width
Change background colour