1
0
mirror of https://github.com/robertkrimen/otto synced 2025-09-28 18:45:22 +08:00
otto/registry/registry.go
2012-10-10 16:10:07 -07:00

48 lines
763 B
Go

/*
Package registry is an expirmental package to facillitate altering the otto runtime via import.
This interface can change at any time.
*/
package registry
var registry []*Entry = make([]*Entry, 0)
type Entry struct {
active bool
source string
}
func newEntry(source string) *Entry {
return &Entry{
active: true,
source: source,
}
}
func (self *Entry) Enable() {
self.active = true
}
func (self *Entry) Disable() {
self.active = false
}
func (self Entry) Source() string {
return self.source
}
func Apply(callback func(Entry)) {
for _, entry := range registry {
if !entry.active {
continue
}
callback(*entry)
}
}
func Register(source string) *Entry {
entry := newEntry(source)
registry = append(registry, entry)
return entry
}