plugin

package
v0.10.1 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2024 License: Apache-2.0 Imports: 8 Imported by: 4

Documentation

Index

Constants

View Source
const CgoEnabled = true

Variables

This section is empty.

Functions

func GetInvokeJsonProxyPtr

func GetInvokeJsonProxyPtr() uint64

func Invoke

func Invoke(method string, args []interface{}, kwargs map[string]interface{}) (result_json string)

func InvokeJson

func InvokeJson(method, args_json, kwargs_json string) (result_json string)

func JSONError

func JSONError(err error) string

func RegisterPlugin

func RegisterPlugin(plugin Plugin)

Register register a new kcl plugin.

func ResetPlugin

func ResetPlugin()

ResetPlugin reset all kcl plugin state.

Types

type BacktraceFrame

type BacktraceFrame struct {
	File string `json:"file,omitempty"`
	Func string `json:"func,omitempty"`
	Line int    `json:"line,omitempty"`
	Col  int    `json:"col,omitempty"`
}

type MethodArgs

type MethodArgs struct {
	Args   []interface{}          // List of positional arguments
	KwArgs map[string]interface{} // Map of keyword arguments
}

MethodArgs represents the arguments passed to a KCL Plugin method. It includes a list of positional arguments and a map of keyword arguments.

func ParseMethodArgs

func ParseMethodArgs(args_json, kwargs_json string) (*MethodArgs, error)

ParseMethodArgs parses JSON strings for positional and keyword arguments and returns a MethodArgs object. args_json: JSON string of positional arguments kwargs_json: JSON string of keyword arguments

func (*MethodArgs) Arg

func (p *MethodArgs) Arg(i int) interface{}

Arg returns the positional argument at the specified index.

func (*MethodArgs) BoolArg added in v0.9.0

func (p *MethodArgs) BoolArg(i int) bool

BoolArg returns the positional argument at the specified index as a bool. It panics if the conversion fails.

func (*MethodArgs) BoolKwArg added in v0.9.0

func (p *MethodArgs) BoolKwArg(name string) bool

BoolKwArg returns the keyword argument with the given name as a bool. It panics if the conversion fails.

func (*MethodArgs) FloatArg

func (p *MethodArgs) FloatArg(i int) float64

FloatArg returns the positional argument at the specified index as a float64. It panics if the conversion fails.

func (*MethodArgs) FloatKwArg

func (p *MethodArgs) FloatKwArg(name string) float64

FloatKwArg returns the keyword argument with the given name as a float64. It panics if the conversion fails.

func (*MethodArgs) GetCallArg added in v0.9.2

func (p *MethodArgs) GetCallArg(index int, key string) any

GetCallArg retrieves an argument by index or key. If the key exists in KwArgs, it returns the corresponding value. Otherwise, it returns the positional argument at the given index.

func (*MethodArgs) IntArg

func (p *MethodArgs) IntArg(i int) int64

IntArg returns the positional argument at the specified index as an int64. It panics if the conversion fails.

func (*MethodArgs) IntKwArg

func (p *MethodArgs) IntKwArg(name string) int64

IntKwArg returns the keyword argument with the given name as an int64. It panics if the conversion fails.

func (*MethodArgs) KwArg

func (p *MethodArgs) KwArg(name string) interface{}

KwArg returns the keyword argument with the given name.

func (*MethodArgs) ListArg added in v0.9.0

func (p *MethodArgs) ListArg(i int) []any

ListArg returns the positional argument at the specified index as a list of any type.

func (*MethodArgs) ListKwArg added in v0.9.0

func (p *MethodArgs) ListKwArg(name string) []any

ListKwArg returns the keyword argument with the given name as a list of any type.

func (*MethodArgs) MapArg added in v0.9.0

func (p *MethodArgs) MapArg(i int) map[string]any

MapArg returns the positional argument at the specified index as a map with string keys and any type values.

func (*MethodArgs) MapKwArg added in v0.9.0

func (p *MethodArgs) MapKwArg(name string) map[string]any

MapKwArg returns the keyword argument with the given name as a map with string keys and any type values.

func (*MethodArgs) StrArg

func (p *MethodArgs) StrArg(i int) string

StrArg returns the positional argument at the specified index as a string.

func (*MethodArgs) StrKwArg

func (p *MethodArgs) StrKwArg(name string) string

StrKwArg returns the keyword argument with the given name as a string.

type MethodResult

type MethodResult struct {
	V interface{} // Result value
}

MethodResult represents the result returned from a KCL Plugin method. It holds the value of the result.

type MethodSpec

type MethodSpec struct {
	Type *MethodType                                   // Specification of the method's type
	Body func(args *MethodArgs) (*MethodResult, error) // Function to execute the method's logic
}

MethodSpec defines the specification for a KCL Plugin method. It includes the method type and the body function which executes the method logic.

func GetMethodSpec

func GetMethodSpec(methodName string) (method MethodSpec, ok bool)

GetMethodSpec get plugin method by name.

type MethodType

type MethodType struct {
	ArgsType   []string          // List of types for positional arguments
	KwArgsType map[string]string // Map of keyword argument names to their types
	ResultType string            // Type of the result
}

MethodType describes the type of a KCL Plugin method's arguments, keyword arguments, and result. It specifies the types of positional arguments, keyword arguments, and the result type.

type PanicInfo

type PanicInfo struct {
	Message string `json:"__kcl_PanicInfo__"`
}

func (*PanicInfo) Error

func (p *PanicInfo) Error() string

func (*PanicInfo) JSONError

func (p *PanicInfo) JSONError() string

type Plugin

type Plugin struct {
	Name      string                // Name of the plugin
	Version   string                // Version of the plugin
	ResetFunc func()                // Reset function for the plugin
	MethodMap map[string]MethodSpec // Map of method names to their specifications
}

Plugin represents a KCL Plugin with metadata and methods. It contains the plugin name, version, a reset function, and a map of methods.

func GetPlugin

func GetPlugin(name string) (plugin Plugin, ok bool)

GetPlugin get plugin object by name.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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