15. Misc

This section documents various functions that do not fit in any other sections.

15.1. Threads

haka.current_thread() → id
Returns:
  • id (number) – The current thread’s index.

Allows to check what thread is currently running.

haka.abort()

Abort current execution. This function will throw an error that will unwind the stack up to the topmost protected call.

15.2. Exit

haka.on_exit(exit_func)
Parameters:
  • exit_func (function) – Function to run at exit time.

Registers a callback that will be called when Haka exits.

15.3. Time

object time

Time object.

haka.time(secs) → t
Parameters:
  • secs (number) – Number of seconds since the epoch (1970-01-01T00:00:00Z ISO 8601).
Returns:
  • t (time) – New time representation.

Build a new time object.

<time>.secs
<time>.nsecs
Type:number

Seconds and nano-seconds as integer value.

const <time>.seconds
Type:number

Seconds as floating point value.

tostring(<time>) → str
Returns:
  • str (string) – Human readable representation of the time.

Convert the time to human readable form.

15.4. General Events

Haka also uses global events to notify for interesting messages. Those events can be used by a regular rule as usual.

event haka.events.started()

Event triggered when the Haka configuration is loaded and Haka is ready to process packets.

event haka.events.exiting()

Event triggered when Haka is exiting.