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.
View on GitHub →-- 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
TAC.new(config)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.
config (table): Optional configuration optionsinstance.registerExtension(name, extension)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.
name (string): The unique name identifier for the extensionextension (table): The extension module (must have .init(tac) method)instance.registerCommand(name, commandDef)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()
name (string): The command name (what users type)commandDef (table): Command definition with fields:instance.addHook(hookName, callback)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 ()
hookName (string): Name of the hook pointcallback (function): The callback function to invokeinstance.registerBackgroundProcess(name, processFunction)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.
name (string): Unique identifier for the processprocessFunction (function): The function to run in parallelinstance.disableBackgroundProcess(name)Disable a background process Marks a registered background process as disabled, preventing it from running. The process will not be started until re-enabled.
name (string): Unique identifier of the background processinstance.enableBackgroundProcess(name)Enable a background process Re-enables a previously disabled background process, allowing it to run.
name (string): Unique identifier of the background processinstance.getProcessStatus(name)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
name (string|nil): Optional process name (returns all processes if nil)instance.executeHooks(hookName)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.
hookName (string): Name of the hook to executeinstance.registerExtensionSettings(extensionName, settingsConfig)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
extensionName (string): Name of the extensionsettingsConfig (table): Configuration with fields:instance.checkExtensionSettings(d)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.
d (table): Optional display interface (uses instance.d if not provided)instance.getServerNfc()Get server NFC reader peripheral Returns the configured server NFC reader peripheral.
instance.require(extensionName)Require an extension Safely loads and returns an extension by name. Returns the extension's exported API or nil if not loaded.
extensionName (string): Name of the extension to requireTAC.loadExtensions(instance, options)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.
instance (table): The TAC instanceoptions (table): Optional configuration (passed to extensionLoader.loadFromDirectory)