1. Introduction

This section contains the reference guide for user that wants to write Haka scripts.

The format of this documentation is presented here.

Note

If you want to contribute to the core of Haka, check the section for developers: Welcome to Haka’s Developer Guide!.

1.1. Module

A module test is used in this example to show how various elements of a module can be used.

Every functions and variables will be prefixed by the module name, in our case: test..

1.2. Function

Each function is described using the following format:

test.func(param1, param2[, param3]) → ret1, ret2
Parameters:
  • param1 (parameter type if needed) – This is how a parameter is described.
  • param2

    ...

Returns:
  • ret1 (return type if needed) – This is how returned value are described.
  • ret2

    ...

A function that is available in a module.

Then the code will follow this declaration:

local a, b = test.func("string", 42)

1.3. Variable

test.data
Type:Data type if needed

A data available on a module.

1.4. Object

An object in Lua is basically a table containing functions and properties. Every object is documented as follows:

object Obj
<Obj>:func(param1) → ret1
Parameters:
  • param1 (parameter type if needed) – This is how a parameter is described.
Returns:
  • ret1 (return type if needed) – This is how returned value are described.

This function is a method that need to be called on an instance of the type Obj in this example.

The : here is used to call method. See the Lua programming language documentation for more detail about it.

local obj = test.build(12)
obj:func()
<Obj>.attr
Type:Attribute type if needed

Attribute of the object.

local obj = test.build(12)
print(obj.attr)
test.build(param) → obj

This function is available on a module. However, it is described in this object because it is related to it. For instance, the function could create an instance of Obj.

1.5. Event

Haka uses events that allow security rules to be hooked to dissectors for instance. An event is triggered by an emitter and received by a listener. It is described as follow:

event test.events.myevent(param1, param2, ...)
Parameters:
  • param1 (parameter type if needed) – This is how a parameter is described.

This description defines two properties:

  • The name of the event (myevent) and how to reference it in order to listen to it or to trigger it.
  • The parameters that a listener will receive.