script

package
v0.0.11 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CallOptionalFunc

func CallOptionalFunc(ctx context.Context, i *interp.Interpreter, packageName, funcName, subject string, args []any) (bool, error)

CallOptionalFunc 调用脚本包中的可选函数;函数不存在时返回 false, nil。 生命周期函数复用 Register 的参数校验规则,并允许函数返回 error。

func CompileAndRegister

func CompileAndRegister(ctx context.Context, source string, options CompileOptions) (*interp.Interpreter, error)

CompileAndRegister 编译脚本源码,并调用脚本包中的 Register 函数。

func CompileFromDir

func CompileFromDir(ctx context.Context, dir string, options CompileOptions) (*interp.Interpreter, string, error)

CompileFromDir 从目录中查找并编译 functions 脚本,返回解释器实例和源码内容。 如果目录中没有 functions 文件,返回 nil, "", nil。

func FindFunctionsPath

func FindFunctionsPath(dir string) string

FindFunctionsPath 返回扩展目录下优先匹配的 functions 脚本路径。 主题和插件共用同一套查找规则:优先 functions.go,其次 functions.goyaegi。

func HookAPIExports

func HookAPIExports() interp.Exports

HookAPIExports 返回主题和插件脚本共用的 hook API yaegi 导出表。 保持唯一来源,避免 internal/plugin 与 internal/theme 各维护一份类型/常量清单。 yaegi 的 Exports API 要求用 reflect.Value 描述宿主侧导出的类型、函数和常量, 这里的反射是解释器边界所必需,不参与业务运行时分发。

func ParseKVArgs

func ParseKVArgs(args []any) map[string]any

ParseKVArgs 解析 key-value 参数对为 map[string]any。 例如 ("n", 5, "tag", "go") → {"n": 5, "tag": "go"}。

Types

type CompileOptions

type CompileOptions struct {
	Subject      string
	PackageName  string
	Exports      interp.Exports
	RegisterArgs []any
}

CompileOptions 描述一段 yaegi 脚本的编译与 Register 调用参数。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL