Skip to content

Module Quick Start

cyberbit edited this page Jul 25, 2026 · 2 revisions

A simple multi-file module example:

--- staticExample/init.lua

return function (api)
    -- input, output, and middleware can be exported, but are all optional
    return {
        input = {
            -- 'parentFolder.ClassName' pattern is tested for multi-file, single-file, and Luz modules
            -- other require patterns may work but are not officially supported
            static = api.require 'staticExample.StaticMetricInputAdapter',
        },

        -- output = {},

        -- middleware = {},
    }
end
--- staticExample/StaticMetricInputAdapter.lua

return function (api)
    -- vendor modules are available from api.vendor
    local fl = api.vendor.fluent

    -- instantiate a new input adapter class
    local StaticMetricInputAdapter = api.mintInput('StaticMetricInputAdapter')

    function StaticMetricInputAdapter:constructor ()
        self:super('constructor')
    end

    -- input read entrypoint
    function StaticMetricInputAdapter:read ()
        return api.MetricCollection{ static = 1 }
    end

    return StaticMetricInputAdapter
end

Modules are loaded automatically from .telem/modules, or from a custom location like this:

local telem = require 'telem'

-- load module as a local variable
local staticExample = telem.module.load('lib.my-modules.staticExample')
-- local adapter = staticExample.input.static

-- autoload directory of custom modules
telem.module.autoload('lib/my-modules')
-- local adapter = telem.input.staticExample.static

The single-file equivalent can be trivially created by replacing api.require with the function from the required file. Luz modules are built from single-file modules using lua bin/luzc.lua module.lua module.luz.

For more complicated base adapter setups, see the Advanced Peripherals module source.

Clone this wiki locally