function-register.go module-register.go
This commit is contained in:
parent
06ab303b9e
commit
6dd8283308
@ -1,25 +1,25 @@
|
||||
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||||
// All rights reserved.
|
||||
|
||||
// function-register.go
|
||||
// module-register.go
|
||||
package expr
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
var functionRegister map[string]func(ExprContext)
|
||||
var moduleRegister map[string]func(ExprContext)
|
||||
|
||||
func registerImport(name string, importFunc func(ExprContext)) {
|
||||
if functionRegister == nil {
|
||||
functionRegister = make(map[string]func(ExprContext))
|
||||
if moduleRegister == nil {
|
||||
moduleRegister = make(map[string]func(ExprContext))
|
||||
}
|
||||
functionRegister[name] = importFunc
|
||||
moduleRegister[name] = importFunc
|
||||
}
|
||||
|
||||
func ImportInContext(ctx ExprContext, name string) (exists bool) {
|
||||
var importFunc func(ExprContext)
|
||||
if importFunc, exists = functionRegister[name]; exists {
|
||||
if importFunc, exists = moduleRegister[name]; exists {
|
||||
importFunc(ctx)
|
||||
}
|
||||
return
|
||||
@ -27,7 +27,7 @@ func ImportInContext(ctx ExprContext, name string) (exists bool) {
|
||||
|
||||
func ImportInContextByGlobPattern(ctx ExprContext, pattern string) (count int, err error) {
|
||||
var matched bool
|
||||
for name, importFunc := range functionRegister {
|
||||
for name, importFunc := range moduleRegister {
|
||||
if matched, err = filepath.Match(pattern, name); err == nil {
|
||||
if matched {
|
||||
count++
|
||||
@ -41,7 +41,7 @@ func ImportInContextByGlobPattern(ctx ExprContext, pattern string) (count int, e
|
||||
}
|
||||
|
||||
func init() {
|
||||
if functionRegister == nil {
|
||||
functionRegister = make(map[string]func(ExprContext))
|
||||
if moduleRegister == nil {
|
||||
moduleRegister = make(map[string]func(ExprContext))
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user