2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-03-28 09:20:41 +00:00

feat(bait): add catchOnce function

This commit is contained in:
TorchedSammy 2021-12-04 17:59:19 -04:00
parent dd45766bae
commit 51b1219003
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD

View File

@ -38,6 +38,7 @@ failed, etc. To find all available hooks, see doc hooks.`)
L.SetField(mod, "throw", luar.New(L, b.bthrow))
L.SetField(mod, "catch", luar.New(L, b.bcatch))
L.SetField(mod, "catchOnce", luar.New(L, b.bcatchOnce))
L.Push(mod)
@ -55,3 +56,9 @@ func (b *Bait) bthrow(name string, args ...interface{}) {
func (b *Bait) bcatch(name string, catcher func(...interface{})) {
b.Em.On(name, catcher)
}
// catchOnce(name, cb)
// Same as catch, but only runs the `cb` once and then removes the hook
func (b *Bait) bcatchOnce(name string, catcher func(...interface{})) {
b.Em.Once(name, catcher)
}