Module dbg

This module provides development-only asserts and other debug guards.

Instead of a regular Lua assert(), use dbg.dassert() which can be toggled at runtime.

dbg.dassert(important_variable ~= nil)

For checking whether the input given to a function is sane, you can use dbg.guard().

dbg:guard(NickelConf.frontLightLevel, "set",
    function(new_intensity)
        assert(type(new_intensity) == "number",
               "Wrong brightness value type (expected number)!")
        assert(new_intensity >= 0 and new_intensity <= 100,
               "Wrong brightness value given!")
    end)

These functions don't do anything when debugging is turned off.

Functions

Dbg:turnOn () Turn on debug mode.
Dbg.guard (_, mod, method, pre_guard, post_guard) Pass a guard function to detect bad input values.
Dbg.dassert (check, msg) Use this instead of a regular Lua assert().
Dbg:turnOff () Turn off debug mode.
Dbg:setVerbose (verbose) Turn on verbose mode.
Dbg:v (...) Simple table dump.
Dbg.log (...) Conditional logging with a stable ref.
Dbg:traceback () Simple traceback.


Functions

Dbg:turnOn ()
Turn on debug mode. This should only be used in tests and at the user's request.
Dbg.guard (_, mod, method, pre_guard, post_guard)
Pass a guard function to detect bad input values.

Parameters:

  • _
  • mod
  • method
  • pre_guard
  • post_guard
Dbg.dassert (check, msg)
Use this instead of a regular Lua assert().

Parameters:

  • check
  • msg
Dbg:turnOff ()
Turn off debug mode. This should only be used in tests and at the user's request.
Dbg:setVerbose (verbose)
Turn on verbose mode. This should only be used in tests and at the user's request.

Parameters:

  • verbose
Dbg:v (...)
Simple table dump.

Parameters:

  • ...
Dbg.log (...)
Conditional logging with a stable ref.

Parameters:

  • ...
Dbg:traceback ()
Simple traceback.
generated by LDoc 1.5.0 Last updated 2024-11-21 07:57:34