summaryrefslogtreecommitdiff
path: root/examples/extensions/greet.lua
diff options
context:
space:
mode:
Diffstat (limited to 'examples/extensions/greet.lua')
-rw-r--r--examples/extensions/greet.lua20
1 files changed, 15 insertions, 5 deletions
diff --git a/examples/extensions/greet.lua b/examples/extensions/greet.lua
index d74095b..38d8ca0 100644
--- a/examples/extensions/greet.lua
+++ b/examples/extensions/greet.lua
@@ -2,17 +2,27 @@
-- Drop this under .panto/extensions/ (project) or your user config's
-- extensions/ dir, then type `/greet` or `/greet <name>` in the REPL.
--
+-- Extensions return an *entry* `{ name, activate }`. The file is always
+-- eval'd, but `activate()` runs only if `name` is permitted by the
+-- `[extensions]` policy — so registration is deferred into activate().
+-- One entry may register any number of tools/commands.
+--
-- Slash-command handlers run synchronously and act by side effect (here,
-- writing to stdout). `args` is the trimmed text after the command name;
-- it is an empty string when none was given. The return value is ignored.
local panto = require("panto")
-panto.ext.register_command {
+return {
name = "greet",
- description = "Print a greeting. Optional args name who to greet.",
- handler = function(args)
- local who = args ~= "" and args or "world"
- io.write("\n[greet] hello, " .. who .. "!\n")
+ activate = function()
+ panto.ext.register_command {
+ name = "greet",
+ description = "Print a greeting. Optional args name who to greet.",
+ handler = function(args)
+ local who = args ~= "" and args or "world"
+ io.write("\n[greet] hello, " .. who .. "!\n")
+ end,
+ }
end,
}