mirror of https://github.com/Hilbis/Hilbish
feat(bait): add catchOnce function
parent
dd45766bae
commit
51b1219003
|
@ -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, "throw", luar.New(L, b.bthrow))
|
||||||
L.SetField(mod, "catch", luar.New(L, b.bcatch))
|
L.SetField(mod, "catch", luar.New(L, b.bcatch))
|
||||||
|
L.SetField(mod, "catchOnce", luar.New(L, b.bcatchOnce))
|
||||||
|
|
||||||
L.Push(mod)
|
L.Push(mod)
|
||||||
|
|
||||||
|
@ -55,3 +56,9 @@ func (b *Bait) bthrow(name string, args ...interface{}) {
|
||||||
func (b *Bait) bcatch(name string, catcher func(...interface{})) {
|
func (b *Bait) bcatch(name string, catcher func(...interface{})) {
|
||||||
b.Em.On(name, catcher)
|
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)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue