summaryrefslogtreecommitdiff
path: root/examples/extensions/greet.lua
blob: 38d8ca012dc4f224c2eb9645db604049a232cbc0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
-- A trivial Lua slash command that greets the user.
-- 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")

return {
    name = "greet",
    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,
}