tac.init v1.4.3

The main package interface for the TAC access control system. This module provides the core functionality for managing card-based access control, including extension management, command registration, hooks, and background process management.

Author: Twijn • License: MIT
View on GitHub →

Examples

-- Basic TAC usage:
local TAC = require("tac")

-- Initialize TAC
local tac = TAC.new({
    autoload_extensions = true,
    extension_dir = "tac/extensions"
})

-- Start the system
tac.run()
-- Create a custom extension:
local MyExtension = {
    name = "my_extension",
    version = "1.0.0",
    description = "My custom extension"
}

function MyExtension.init(tac)
    -- Access TAC functionality
    local cards = tac.cards.getAll()
    tac.logger.logAccess({...})
    
    -- Load other extensions
    local shopk = tac.require("shopk_access")
    
    -- Register commands
    tac.registerCommand("mycommand", {...})
end

return MyExtension

Functions

TAC.new(config)

View source

Initialize TAC with configuration Creates a new TAC instance with the provided configuration. This is the main entry point for setting up the access control system.

Parameters:
Returns: table A new TAC instance with methods for extension/command registration

instance.registerExtension(name, extension)

View source

Register an extension Registers a TAC extension module. If the extension has an init function, it will be called immediately with the TAC instance. Extensions can register commands, hooks, and background processes.

Parameters:

instance.registerCommand(name, commandDef)

View source

Register a command Registers a new command that can be executed from the TAC command prompt. Commands can include autocompletion and help text. - description (string): Brief description of the command - complete (function): Autocomplete function(args) -> suggestions - execute (function): Execution function(args, d) where d has .mess() and .err()

Parameters:

instance.addHook(hookName, callback)

View source

Add a hook Registers a callback function for a specific hook point in TAC's execution. Multiple callbacks can be registered for the same hook. Available hooks: - beforeAccess: Called before access check (card, door, data, side) - afterAccess: Called after access check (granted, matchReason, card, door) - beforeCommand: Called before command execution (commandName, args) - afterCommand: Called after command execution (commandName, args, success) - beforeShutdown: Called before TAC shuts down ()

Parameters:

instance.registerBackgroundProcess(name, processFunction)

View source

Register a background process Registers a function to run in parallel with the main TAC event loop. Background processes are useful for monitoring, periodic tasks, or maintaining connections to external services.

Parameters:

instance.disableBackgroundProcess(name)

View source

Disable a background process Marks a registered background process as disabled, preventing it from running. The process will not be started until re-enabled.

Parameters:
Returns: boolean True if process was disabled, false if process not found

instance.enableBackgroundProcess(name)

View source

Enable a background process Re-enables a previously disabled background process, allowing it to run.

Parameters:
Returns: boolean True if process was enabled, false if process not found

instance.getProcessStatus(name)

View source

Get process status Returns status information for a specific background process or all processes. - status (string): Current status ("registered", "running", "disabled", etc.) - startTime (number|nil): When process started - lastError (string|nil): Last error message if failed - restartCount (number): Number of times process has restarted

Parameters:
Returns: table Status information with fields:

instance.executeHooks(hookName)

View source

Execute hooks Triggers all registered callbacks for a specific hook point. If any callback returns false, the hook execution stops and returns false with an optional message.

Parameters:
Returns: string|nil Optional message from hook (e.g. reason for denial)

instance.registerExtensionSettings(extensionName, settingsConfig)

View source

Register extension settings requirements Declares settings that an extension requires. TAC will prompt for missing settings when the extension is loaded. - title (string, optional): Form title for settings prompt - required (table): Array of setting definitions, each with: - key (string): Settings key to store value - label (string): Display label in form - type (string): "text", "number", "select", or "peripheral" - default (any, optional): Default value - validate (function, optional): Validation function - options (table, for "select"): Array of options - filter (string, for "peripheral"): Peripheral type filter

Parameters:

instance.checkExtensionSettings(d)

View source

Check for missing extension settings and prompt if needed Validates that all required extension settings are configured. If any are missing, prompts the user with a form to enter them.

Parameters:

instance.getServerNfc()

View source

Get server NFC reader peripheral Returns the configured server NFC reader peripheral.

Returns: table|nil Server NFC reader peripheral, or nil if not configured

instance.require(extensionName)

View source

Require an extension Safely loads and returns an extension by name. Returns the extension's exported API or nil if not loaded.

Parameters:
Returns: string|nil Error message if extension not available

instance.accessLoop()

View source

Main access control loop

instance.commandLoop()

View source

Command line interface loop

instance.start()

View source

Start the TAC system

instance.shutdown()

View source

Shutdown the TAC system gracefully

TAC.loadExtensions(instance, options)

View source

Load extensions from extensions directory Load extensions from directory Discovers and loads all extensions using the extension loader system. Handles dependencies, errors gracefully, and provides detailed feedback.

Parameters:
Returns: table Results with loaded, failed, and skipped extensions