{"modulePath":"gitlab.git.nrw/divekit/divekit-cli","version":"v0.0.0-20261127190501-96442b9bdee1","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package lua\n\nPackage lua provides Lua scripting engine integration\n\n## Constants\n\n```go\nconst (\n\tHookEnable  = \"enable\"\n\tHookDisable = \"disable\"\n\tHookUpdate  = \"update\"\n)\n```\nLifecycles a plugin hook registers a callback for. The names are contract surface: hooks/init.lua calls dk.hooks.\\\u003clifecycle\u003e(fn), and the CLI runs the callback of the lifecycle the command it is in belongs to.\n\n```go\nconst (\n\tHookEditInsertXML  = \"insert_xml\"\n\tHookEditTextBlock  = \"text_block\"\n\tHookEditCreateFile = \"create_file\"\n)\n```\nEdit operations a hook requests through ctx.edits. They mirror the operation families of the edit-plan executor, which is what validates, previews, and applies them; the runtime only collects what a callback asked for, so a hook never writes a file itself.\n\n## Functions\n\n```go\nfunc IsHookTimeout(err error) bool\n```\nIsHookTimeout reports whether err is the wall-clock stop of a hook rather than a failure of the script itself, which is what lets a caller say that a hook ran too long instead of that it was wrong.\n\n```go\nfunc WithTimeout[T any](ctx context.Context, L *glua.LState, d time.Duration, fn func() (T, error)) (T, error)\n```\nWithTimeout executes a function with a timeout\n\n## Types\n\n```go\ntype Engine struct {\n\tL *glua.LState\n\t// contains filtered or unexported fields\n}\n```\nEngine is a Lua scripting engine using gopher-lua (enabled with build tag 'lua')\n\n```go\nfunc NewEngine(options ...Options) *Engine\n```\nNewEngine creates a new Lua scripting engine instance\n\n```go\nfunc (e *Engine) ClearForTests()\n```\nClearForTests resets mutable state used by tests (transformers and maps)\n\n```go\nfunc (e *Engine) CollectVariableTransformers() []contracts.VariableTransformer\n```\nCollectVariableTransformers returns Go adapters for all registered Lua transformers\n\n```go\nfunc (e *Engine) Emit(ctx context.Context, event string, luaCtx any) error\n```\nEmit triggers event handlers registered via dk.hooks.on()\n\n```go\nfunc (e *Engine) Init() error\n```\nInit initializes the Lua engine and sets up the execution environment\n\n```go\nfunc (e *Engine) LanguagesForPath(path string) []string\n```\nLanguagesForPath resolves the effective languages for a given file path. Always includes \"common\" first. If a mapping is configured, applies specific globs first then '\\*' fallback; otherwise uses all loaded packs.\n\n```go\nfunc (e *Engine) LoadLanguages(ctx context.Context, langs []string) error\n```\nLoadLanguages loads the given language packs in order (in addition to 'common').\n\n```go\nfunc (e *Engine) LoadRunWorkflow(ctx context.Context, path string) (bool, error)\n```\nLoadRunWorkflow loads a run workflow script and reports whether workflow callbacks were registered.\n\n```go\nfunc (e *Engine) ResetForTests()\n```\nResetForTests fully resets the engine for testing (including Lua state)\n\n```go\nfunc (e *Engine) RunFile(ctx context.Context, path string) error\n```\nRunFile loads and executes a Lua script file\n\n```go\nfunc (e *Engine) RunFileWithCtx(ctx context.Context, path string, luaCtx any) error\n```\nRunFileWithCtx loads a Lua script and, if it returns a function, calls it with dk and a context available under dk.run\n\n```go\nfunc (e *Engine) RunWorkflowCleanup(ctx context.Context, workflowCtx any) error\n```\nRunWorkflowCleanup executes all registered dk.run.cleanup callbacks.\n\n```go\nfunc (e *Engine) RunWorkflowPrepare(ctx context.Context, workflowCtx any) error\n```\nRunWorkflowPrepare executes all registered dk.run.prepare callbacks.\n\n```go\nfunc (e *Engine) RunWorkflowRepo(ctx context.Context, workflowCtx any) error\n```\nRunWorkflowRepo executes the registered dk.run.each callback for one repository.\n\n```go\nfunc (e *Engine) SetExtensionsMap(m map[string][]string)\n```\nSetExtensionsMap stores extension-to-language mapping used by higher-level file hook context creation.\n\n```go\ntype HookEdit struct {\n\tKind    string\n\tPath    string\n\tAnchor  string\n\tContent string\n}\n```\nHookEdit is one operation a hook collected through ctx.edits. It carries no behaviour: the executor decides what a family means, so the runtime and the declarative front end hand it the same data.\n\n```go\ntype HookHost interface {\n\t// Fragment reads a file the hook repository ships next to its script.\n\tFragment(name string) (string, error)\n\t// Glob returns the working-tree files matching a pattern, read-only.\n\tGlob(pattern string) ([]string, error)\n\t// Read returns the content of one working-tree file, read-only.\n\tRead(path string) (string, error)\n\t// Log reports one message of the hook to the maintainer.\n\tLog(message string)\n}\n```\nHookHost is everything a hook callback may reach outside its own script. Every capability is a method here rather than an ambient library, so what a hook can do is decided by the CLI that lends it the host.\n\n```go\ntype HookScript struct {\n\t// contains filtered or unexported fields\n}\n```\nHookScript is a loaded hooks/init.lua with the lifecycle callbacks it registered. Loading runs the top level of the script, which is what performs the registrations, so a caller that must not execute untrusted code has to decide before it loads rather than before it runs a callback.\n\n```go\nfunc LoadHookScript(ctx context.Context, name, source string, timeout time.Duration) (*HookScript, error)\n```\nLoadHookScript runs source in a sandboxed Lua state and returns the script with the lifecycle callbacks it registered. name is the path the script was fetched from and becomes the chunk name, so a failure names the file and the line a maintainer can look at.\n\n```go\nfunc (s *HookScript) Close()\n```\nClose releases the Lua state. A script is loaded per command, so nothing outlives the run that asked for it.\n\n```go\nfunc (s *HookScript) Registers(lifecycle string) bool\n```\nRegisters reports whether the script carries a callback for one lifecycle, which is what decides whether a hook or the declarative edits of the same repository produce the plan.\n\n```go\nfunc (s *HookScript) Run(ctx context.Context, lifecycle string, host HookHost) ([]HookEdit, error)\n```\nRun calls the callback of one lifecycle and returns the operations it collected. A lifecycle without a callback yields no operation and no error, so a script that only handles enabling stays silent everywhere else.\n\n```go\ntype Options struct {\n\t// Sandbox controls whether process/file-system standard libraries are hidden.\n\tSandbox bool\n\t// ScriptTimeout limits each run script and each dk.run callback. Zero keeps the default.\n\tScriptTimeout time.Duration\n}\n```\nOptions configures a Lua engine instance.\n\n```go\ntype Transformer struct {\n\tL *glua.LState\n\t// contains filtered or unexported fields\n}\n```\nTransformer adapts a Lua transform function to Go VariableTransformer\n\n```go\nfunc (lt *Transformer) GetTokenName() string\n```\nGetTokenName returns the token name for this transformer\n\n```go\nfunc (lt *Transformer) Transform(className string) string\n```\nTransform applies the Lua transformation function to a class name\n\n","path":"gitlab.git.nrw/divekit/divekit-cli/internal/scripting/lua","name":"lua","synopsis":"Package lua provides Lua scripting engine integration","isRedistributable":true}
