Skip to content

AliasMgr: Examples

Damian edited this page Sep 22, 2022 · 1 revision

So, how do you USE it?

It's pretty simple, really. First, you need to make a new aliasmgr. As always, I use the require assuming you've installed the MDK package, if you've included it as part of your own package, replace MDK with name of your package. Also, I recommend wrapping your regular expressions in [[]] so that you don't have to escape all the \ characters. [[\w]] would have to be "\\w" otherwise.

local aliasmgr = require("MDK.aliasmgr")
demonnic = demonnic or {}
demonnic.amgr = demonnic.amgr or aliasmgr:new()

That's it. Nothing to pass to the new function. Then you can start populating it with aliases

This creates an alias named "test alias" which matches ^test1 (\w+) (.*) and displays the matches table.

local amgr = demonnic.amgr
amgr:register("test alias", [[^test1 (\w+) (.*)]], function() display(matches) end)

And so does this, replacing the previous definition with the new one.

amgr:add("test alias", [[^test1 (\w+) (.*)]], [[display(matches)]])

For a kill alias to k <target> you could do

amgr:register("kill", [[^k (\w+)]], function() send("kill " .. matches[2]) end)

To list the aliases registered you can do

display(amgr:getAliases())

Which might return something like this. Disabled aliases will have -1 for a handlerID.

{
  kill = {
    func = <function 1>,
    handlerID = 64,
    regex = "^k (\\w+)"
  },
  ["test alias"] = {
    func = "display(matches)",
    handlerID = 63,
    regex = "^test1 (\\w+) (.*)"
  }
}

To temporary disable the test alias

amgr:disable("test alias")

And to enable it again

amgr:enable("test alias")

And if you want to get rid of it altogether.

amgr:kill("test alias")
-- or
amgr:delete("test alias")

And if you want to get rid of all of the managed aliases

amgr:killAll()
-- or
amgr:deleteAll()