tac.extensions._example v1.0.1

This file demonstrates how to create a TAC extension. Extensions can register commands, add hooks to TAC events, and provide custom functionality.

Author: Twijn • License: MIT
View on GitHub →

Examples

-- To use this extension from another extension:
function MyExtension.init(tac)
    -- Load the example extension
    local example = tac.require("example")
    
    -- Call exported methods
    local stats = example.getStats()
    print("Processed " .. stats.processedCount .. " messages")
    
    -- Use optional dependencies
    local result = example.useOptionalExtension()
    
    -- Process a message
    example.processMessage("Hello, TAC!")
end

Functions

MyExtension.init()

View source

To use this extension from another extension:

ExampleExtension.init(tac)

View source

Initialize the extension This function is called when the extension is loaded by TAC. Use this to: - Register commands with tac.registerCommand() - Add hooks with tac.addHook() - Register background processes with tac.registerBackgroundProcess() - Access TAC settings, cards, doors, etc. - registerCommand(name, commandDef): Register a new command - registerExtension(name, extension): Register an extension - addHook(hookName, callback): Add a hook callback - registerBackgroundProcess(name, fn): Register a background process - settings: Persistent settings storage - cards: Persistent card storage - doors: Persistent door storage - logger: Logger instance

Parameters:

ExampleExtension.customFunction()

View source

Custom function that can be called by other extensions Demonstrates how extensions can provide APIs for inter-extension communication.

Returns: string A greeting message

ExampleExtension.onCardCreated(cardData)

View source

Hook for card creation events This function will be called when cards are created (if hooked into TAC). Can be used to extend or validate card data.

Parameters:

ExampleExtension.useOptionalExtension(tac)

View source

Example of safely requiring another extension Demonstrates how to check if an extension is loaded and access its functionality. This is useful for optional dependencies or inter-extension communication.

Parameters:
Returns: boolean True if extension was found and used

ExampleExtension.processMessage(message)

View source

Example API method that other extensions can call Shows how to export methods that other extensions can use.

Parameters:
Returns: string Processed message

ExampleExtension.getStats()

View source

Get extension statistics Example of exposing data through the extension API.

Returns: table Statistics object