moved a subset of source file to the kern package

This commit is contained in:
2026-04-27 19:43:37 +02:00
parent f100adead3
commit 4d910dd069
107 changed files with 2080 additions and 1380 deletions
+17 -13
View File
@@ -10,6 +10,8 @@ import (
"os"
"plugin"
"strings"
"git.portale-stac.it/go-pkg/expr/kern"
)
var pluginRegister map[string]*plugin.Plugin
@@ -39,12 +41,12 @@ func makePluginName(name string) (decorated string) {
return
}
func importPlugin( /*ctx ExprContext,*/ dirList []string, name string) (err error) {
func importPlugin(ctx kern.ExprContext, dirList []string, name string) (err error) {
var filePath string
var p *plugin.Plugin
var sym plugin.Symbol
var moduleName string
var importFunc func(ExprContext)
var importFunc func(kern.ExprContext)
var ok bool
decoratedName := makePluginName(name)
@@ -71,7 +73,7 @@ func importPlugin( /*ctx ExprContext,*/ dirList []string, name string) (err erro
}
if deps := *sym.(*[]string); len(deps) > 0 {
// var count int
if err = loadModules(dirList, deps); err != nil {
if err = loadModules(ctx, dirList, deps); err != nil {
return
}
}
@@ -80,33 +82,35 @@ func importPlugin( /*ctx ExprContext,*/ dirList []string, name string) (err erro
return
}
if importFunc, ok = sym.(func(ExprContext)); !ok {
if importFunc, ok = sym.(func(kern.ExprContext)); !ok {
err = fmt.Errorf("plugin %q does not provide a valid import function", decoratedName)
return
}
registerPlugin(moduleName, p)
importFunc(globalCtx)
if globalCtx := ctx.GetGlobal(); globalCtx != nil {
importFunc(globalCtx)
}
return
}
func importPluginFromSearchPath(name any) (count int, err error) {
func importPluginFromSearchPath(ctx kern.ExprContext, name any) (count int, err error) {
var moduleSpec any
var it Iterator
dirList := buildSearchDirList("plugin", ENV_EXPR_PLUGIN_PATH)
var it kern.Iterator
dirList := buildSearchDirList(ctx, "plugin", ENV_EXPR_PLUGIN_PATH)
count = 0
if it, err = NewIterator(name); err != nil {
return
}
for moduleSpec, err = it.Next(); err == nil; moduleSpec, err = it.Next() {
if module, ok := moduleSpec.(string); ok {
if err = importPlugin(dirList, module); err != nil {
if err = importPlugin(ctx, dirList, module); err != nil {
break
}
count++
} else {
err = fmt.Errorf("expected string as item nr %d, got %s", it.Index()+1, TypeName(moduleSpec))
err = fmt.Errorf("expected string as item nr %d, got %s", it.Index()+1, kern.TypeName(moduleSpec))
break
}
}
@@ -116,10 +120,10 @@ func importPluginFromSearchPath(name any) (count int, err error) {
return
}
func loadModules(dirList []string, moduleNames []string) (err error) {
func loadModules(ctx kern.ExprContext, dirList []string, moduleNames []string) (err error) {
for _, name := range moduleNames {
if err1 := importPlugin(dirList, name); err1 != nil {
if !ImportInContext(name) {
if err1 := importPlugin(ctx, dirList, name); err1 != nil {
if !ImportInContext(ctx, name) {
err = err1
break
}