Plugin Discovery and Loading
Scan directories for plugin files and load them with require or loadfile.
What Is a Plugin Architecture?
A plugin architecture allows third-party code to extend an application without modifying its core. Lua's require and dynamic loading make this natural.
Plugin Discovery by Convention
Scan a directory for *.lua files matching a naming convention, then load each as a plugin.
local function discoverPlugins(dir)
local plugins = {}
-- platform-specific dir scan; here a mock example
for _, name in ipairs({"logger", "cache", "auth"}) do
local ok, mod = pcall(require, dir .. "." .. name)
if ok then plugins[name] = mod end
end
return plugins
endAll lessons in this course
- Plugin Discovery and Loading
- Plugin API and Hook System
- Sandboxing Plugin Execution
- Versioning and Dependency Management