0Pricing
Lua Academy · Lesson

Plugin API and Hook System

Define a plugin API table and register hooks for lifecycle events.

What Is a Hook System?

A hook system allows plugins to register callbacks for specific application lifecycle events. The app calls all registered hooks at the appropriate time.

The Application Object

The app object is passed to plugins during init. It exposes the hook registration API.

local App = {}
App.__index = App
App._hooks = {}
function App:on(event, fn)
  self._hooks[event] = self._hooks[event] or {}
  table.insert(self._hooks[event], fn)
end
function App:emit(event, ...)
  for _, fn in ipairs(self._hooks[event] or {}) do
    fn(...)
  end
end

All lessons in this course

  1. Plugin Discovery and Loading
  2. Plugin API and Hook System
  3. Sandboxing Plugin Execution
  4. Versioning and Dependency Management
← Back to Lua Academy