Documentation
¶
Index ¶
- func FromGo(v interface{}) object.Object
- func Get(script string) (*ast.Program, bool)
- func Set(script string, program *ast.Program)
- func ToGo(obj object.Object) interface{}
- func ToGoError(obj object.Object) error
- type Scriptling
- func (p *Scriptling) CallFunction(name string, args ...interface{}) (object.Object, error)
- func (p *Scriptling) CallFunctionWithContext(ctx context.Context, name string, args ...interface{}) (object.Object, error)
- func (p *Scriptling) EnableOutputCapture()
- func (p *Scriptling) Eval(input string) (object.Object, error)
- func (p *Scriptling) EvalWithContext(ctx context.Context, input string) (object.Object, error)
- func (p *Scriptling) EvalWithTimeout(timeout time.Duration, input string) (object.Object, error)
- func (p *Scriptling) GetOutput() string
- func (p *Scriptling) GetVar(name string) (interface{}, object.Object)
- func (p *Scriptling) GetVarAsBool(name string) (bool, object.Object)
- func (p *Scriptling) GetVarAsDict(name string) (map[string]object.Object, object.Object)
- func (p *Scriptling) GetVarAsFloat(name string) (float64, object.Object)
- func (p *Scriptling) GetVarAsInt(name string) (int64, object.Object)
- func (p *Scriptling) GetVarAsList(name string) ([]object.Object, object.Object)
- func (p *Scriptling) GetVarAsString(name string) (string, object.Object)
- func (p *Scriptling) Import(names interface{}) error
- func (p *Scriptling) RegisterFunc(name string, ...)
- func (p *Scriptling) RegisterLibrary(name string, lib *object.Library)
- func (p *Scriptling) RegisterScriptFunc(name string, script string) error
- func (p *Scriptling) RegisterScriptLibrary(name string, script string) error
- func (p *Scriptling) SetObjectVar(name string, obj object.Object) error
- func (p *Scriptling) SetOnDemandLibraryCallback(callback func(*Scriptling, string) bool)
- func (p *Scriptling) SetVar(name string, value interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func FromGo ¶
FromGo converts a Go interface{} value to a scriptling Object. It handles primitive types (nil, bool, int, float, string), nested structures (maps, slices), and falls back to JSON marshaling for unknown types.
Types ¶
type Scriptling ¶
type Scriptling struct {
// contains filtered or unexported fields
}
func New ¶
func New() *Scriptling
func (*Scriptling) CallFunction ¶
func (p *Scriptling) CallFunction(name string, args ...interface{}) (object.Object, error)
CallFunction calls a registered function by name with Go arguments. Args are Go types (int, string, etc.) that will be converted to Object. Returns object.Object - use .AsInt(), .AsString(), etc. to extract value.
Works with both Go-registered functions (via RegisterFunc) and script-defined functions.
Keyword arguments can be passed as the last argument using map[string]interface{}.
Example:
p.RegisterFunc("add", addFunc)
result, err := p.CallFunction("add", 10, 32)
sum, _ := result.AsInt()
// With keyword arguments
result, err := p.CallFunction("format", "value", map[string]interface{}{"prefix": ">>"})
func (*Scriptling) CallFunctionWithContext ¶
func (p *Scriptling) CallFunctionWithContext(ctx context.Context, name string, args ...interface{}) (object.Object, error)
CallFunctionWithContext calls a registered function by name with Go arguments and a context. The context can be used for cancellation or timeouts. Args are Go types (int, string, etc.) that will be converted to Object. Returns object.Object - use .AsInt(), .AsString(), etc. to extract value.
Works with both Go-registered functions (via RegisterFunc) and script-defined functions.
Keyword arguments can be passed as the last argument using map[string]interface{}.
Example:
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
result, err := p.CallFunctionWithContext(ctx, "add", 10, 32)
sum, _ := result.AsInt()
// With keyword arguments
result, err := p.CallFunctionWithContext(ctx, "format", "value", map[string]interface{}{"prefix": ">>"})
func (*Scriptling) EnableOutputCapture ¶
func (p *Scriptling) EnableOutputCapture()
EnableOutputCapture enables capturing print output instead of sending to stdout
func (*Scriptling) Eval ¶
func (p *Scriptling) Eval(input string) (object.Object, error)
Eval executes script without timeout (backwards compatible)
func (*Scriptling) EvalWithContext ¶
EvalWithContext executes script with context for timeout/cancellation
func (*Scriptling) EvalWithTimeout ¶
EvalWithTimeout executes script with timeout
func (*Scriptling) GetOutput ¶
func (p *Scriptling) GetOutput() string
GetOutput returns captured output and clears the buffer
func (*Scriptling) GetVarAsBool ¶
func (p *Scriptling) GetVarAsBool(name string) (bool, object.Object)
func (*Scriptling) GetVarAsDict ¶
func (*Scriptling) GetVarAsFloat ¶
func (p *Scriptling) GetVarAsFloat(name string) (float64, object.Object)
func (*Scriptling) GetVarAsInt ¶
func (p *Scriptling) GetVarAsInt(name string) (int64, object.Object)
func (*Scriptling) GetVarAsList ¶
func (*Scriptling) GetVarAsString ¶
func (p *Scriptling) GetVarAsString(name string) (string, object.Object)
Convenience methods for type-safe variable access
func (*Scriptling) Import ¶
func (p *Scriptling) Import(names interface{}) error
Import imports a library into the current environment, making it available for use without needing an import statement in scripts
func (*Scriptling) RegisterFunc ¶
func (*Scriptling) RegisterLibrary ¶
func (p *Scriptling) RegisterLibrary(name string, lib *object.Library)
RegisterLibrary registers a new library that can be imported by scripts
func (*Scriptling) RegisterScriptFunc ¶
func (p *Scriptling) RegisterScriptFunc(name string, script string) error
RegisterScriptFunc registers a function written in Scriptling The script should define a function and this method will extract it and register it by name
func (*Scriptling) RegisterScriptLibrary ¶
func (p *Scriptling) RegisterScriptLibrary(name string, script string) error
RegisterScriptLibrary registers a library written in Scriptling The script should define functions/values that will be available when the library is imported
func (*Scriptling) SetObjectVar ¶
func (p *Scriptling) SetObjectVar(name string, obj object.Object) error
SetObjectVar sets a variable in the environment from a scriptling Object. This is useful when you already have a scriptling object (like an Instance) and want to set it directly without converting from Go types.
func (*Scriptling) SetOnDemandLibraryCallback ¶
func (p *Scriptling) SetOnDemandLibraryCallback(callback func(*Scriptling, string) bool)
SetOnDemandLibraryCallback sets a callback that is called when a library import fails The callback receives the Scriptling instance and the library name, and should return true if it successfully registered the library using RegisterLibrary or RegisterScriptLibrary
func (*Scriptling) SetVar ¶
func (p *Scriptling) SetVar(name string, value interface{}) error
Directories
¶
| Path | Synopsis |
|---|---|
|
Package build contains build-time version information for Scriptling
|
Package build contains build-time version information for Scriptling |
|
examples
|
|
|
logging
command
|
|
|
mcp-client/direct
command
|
|
|
mcp-client/shared
command
|
|
|
mcp-client/with-openai
command
|
|
|
mcp-client/with-openai-instance
command
|
|
|
multi-environment
command
|
|
|
openai/instance
command
|
|
|
openai/shared
command
|
|
|
openai/streaming
command
|
|
|
Package extlibs provides external libraries that need explicit registration
|
Package extlibs provides external libraries that need explicit registration |
|
tools
|
|
|
getversion
command
|