Documentation ¶
Index ¶
- Constants
- Variables
- func HaveYakcCache(code string) ([]byte, bool)
- func HaveYakcCacheWithKey(code string, key []byte) ([]byte, bool)
- func Import(name string, f interface{})
- func InjectContextBuiltinFunction(engine *Engine)
- func IsCryptoYakc(b []byte) bool
- func IsNormalYakc(b []byte) bool
- func IsYakc(b []byte) bool
- func SaveYakcCache(code string, yakc []byte)
- func SaveYakcCacheWithKey(code string, yakc []byte, key []byte)
- type Engine
- func (n *Engine) CallYakFunction(ctx context.Context, funcName string, params []interface{}) (interface{}, error)
- func (n *Engine) CallYakFunctionNative(ctx context.Context, function *yakvm.Function, params ...interface{}) (interface{}, error)
- func (n *Engine) Compile(code string) ([]*yakvm.Code, error)
- func (n *Engine) CopyVars() map[string]interface{}
- func (n *Engine) EnableDebug()
- func (n *Engine) EnableStrictMode()
- func (n *Engine) Eval(ctx context.Context, code string) error
- func (n *Engine) EvalInline(ctx context.Context, code string) error
- func (n *Engine) EvalWithInline(ctx context.Context, code string, inline bool) error
- func (n *Engine) ExecYakc(ctx context.Context, b []byte, key []byte, code string) error
- func (n *Engine) ExecYakcWithCode(ctx context.Context, b []byte, key []byte, code string) error
- func (n *Engine) ExecuteAsBooleanExpression(expr string, dependencies map[string]interface{}) (bool, error)
- func (n *Engine) ExecuteAsExpression(expr string, dependencies map[string]interface{}) (interface{}, error)
- func (n *Engine) FormattedAndSyntaxChecking(code string) (string, error)
- func (n *Engine) GetCurrentScope() (*yakvm.Scope, error)
- func (n *Engine) GetFntable() map[string]any
- func (n *Engine) GetLastStackValue() (*yakvm.Value, error)
- func (n *Engine) GetScopeInspects() ([]*ScopeValue, error)
- func (n *Engine) GetSymNames() []string
- func (n *Engine) GetVM() *yakvm.VirtualMachine
- func (n *Engine) GetVar(name string) (interface{}, bool)
- func (n *Engine) HaveEvaluatedCode() bool
- func (n *Engine) ImportLibs(libs map[string]interface{})
- func (n *Engine) LoadCode(ctx context.Context, code string, table map[string]interface{}) error
- func (n *Engine) Marshal(code string, key []byte) ([]byte, error)
- func (n *Engine) MustCompile(code string) []*yakvm.Code
- func (n *Engine) OverrideRuntimeGlobalVariables(parent map[string]any)
- func (n *Engine) RunFile(ctx context.Context, path string) error
- func (e *Engine) RuntimeInfo(infoType string, params ...any) (res any, err error)
- func (n *Engine) SafeCallYakFunction(ctx context.Context, funcName string, params []interface{}) (result interface{}, err error)
- func (n *Engine) SafeEval(ctx context.Context, code string) (err error)
- func (n *Engine) SafeEvalInline(ctx context.Context, code string) (err error)
- func (n *Engine) SafeExecYakc(ctx context.Context, b []byte, key []byte, code string) (fErr error)
- func (n *Engine) SafeExecYakcWithCode(ctx context.Context, b []byte, key []byte, code string) (fErr error)
- func (n *Engine) SetDebugCallback(callback func(*yakvm.Debugger))
- func (n *Engine) SetDebugInit(callback func(*yakvm.Debugger))
- func (n *Engine) SetDebugMode(debug bool)
- func (n *Engine) SetExternalVarGetter(f func(name string) (any, bool))
- func (e *Engine) SetSandboxMode(mode bool)
- func (n *Engine) SetSourceFilePath(path string)
- func (e *Engine) SetStrictMode(b bool)
- func (n *Engine) SetVars(m map[string]any)
- func (n *Engine) UnMarshal(b []byte, key []byte, code string) (*yakvm.SymbolTable, []*yakvm.Code, error)
- func (n *Engine) Var(name string) interface{}
- func (e *Engine) YakBuiltinEval(code string)
- func (e *Engine) YakBuiltinGetFromScope(v string, vals ...any) any
- func (e *Engine) YakBuiltinGetScopeInspects() ([]*ScopeValue, error)
- func (e *Engine) YakBuiltinfmt(code string) string
- func (e *Engine) YakBuiltinfmtWithError(code string) (string, error)
- type Executor
- type FakeCompiler
- type FakeVM
- type ScopeValue
Constants ¶
View Source
const YAKC_CACHE_MAX_LENGTH = 300
Variables ¶
View Source
var ( MAGIC_NUMBER = []byte{0xbc, 0xed} CRYPTO_MAGIC_NUMBER = []byte{0xcc, 0xed} )
Functions ¶
func HaveYakcCache ¶
func InjectContextBuiltinFunction ¶ added in v1.2.9
func InjectContextBuiltinFunction(engine *Engine)
func IsCryptoYakc ¶
func IsNormalYakc ¶
func SaveYakcCache ¶
func SaveYakcCacheWithKey ¶
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) CallYakFunction ¶
func (n *Engine) CallYakFunction(ctx context.Context, funcName string, params []interface{}) (interface{}, error)
函数调用时如果不加锁,并发会有问题
func (*Engine) CallYakFunctionNative ¶
func (*Engine) EnableDebug ¶
func (n *Engine) EnableDebug()
func (*Engine) EnableStrictMode ¶
func (n *Engine) EnableStrictMode()
func (*Engine) EvalWithInline ¶
func (*Engine) ExecYakcWithCode ¶
func (*Engine) ExecuteAsBooleanExpression ¶
func (*Engine) ExecuteAsExpression ¶
func (*Engine) FormattedAndSyntaxChecking ¶
func (*Engine) GetFntable ¶
func (*Engine) GetScopeInspects ¶
func (n *Engine) GetScopeInspects() ([]*ScopeValue, error)
func (*Engine) GetSymNames ¶
func (*Engine) GetVM ¶
func (n *Engine) GetVM() *yakvm.VirtualMachine
func (*Engine) HaveEvaluatedCode ¶
func (*Engine) ImportLibs ¶
func (*Engine) OverrideRuntimeGlobalVariables ¶
func (*Engine) RuntimeInfo ¶ added in v1.3.3
func (*Engine) SafeCallYakFunction ¶ added in v1.3.3
func (*Engine) SafeEvalInline ¶
func (*Engine) SafeExecYakc ¶
func (*Engine) SafeExecYakcWithCode ¶
func (*Engine) SetDebugCallback ¶
func (*Engine) SetDebugInit ¶
func (*Engine) SetDebugMode ¶
func (*Engine) SetExternalVarGetter ¶ added in v1.2.8
func (*Engine) SetSandboxMode ¶ added in v1.3.1
func (*Engine) SetSourceFilePath ¶
func (*Engine) SetStrictMode ¶ added in v1.2.3
func (*Engine) YakBuiltinEval ¶ added in v1.2.9
eval 执行任意 Yak 代码 这个函数是存在副作用的,即能够获取和改变当前引擎中的上下文 Example: ``` a = 1 eval("a++") assert a == 2 ```
func (*Engine) YakBuiltinGetFromScope ¶ added in v1.2.9
getFromScope 获取当前作用域中的变量,返回变量值 Example: ``` a, b = 1, "yak" { assert getFromScope("a") == 1 } { assert getFromScope("b") == "yak" } ```
func (*Engine) YakBuiltinGetScopeInspects ¶ added in v1.2.9
func (e *Engine) YakBuiltinGetScopeInspects() ([]*ScopeValue, error)
getScopeInspects 获取当前作用域中的所有变量,返回 ScopeValue 结构体引用切片 Example: ``` a, b = 1, "yak" values, err = getScopeInspects() for v in values { println(v.Value) } ```
func (*Engine) YakBuiltinfmt ¶ added in v1.2.9
yakfmt 格式化任意 Yak 代码,返回格式化后的代码 Example: ``` yakfmt("for { println(`hello yak`) }") ```
type FakeCompiler ¶
type FakeCompiler struct {
// contains filtered or unexported fields
}
func (*FakeCompiler) GetErrors ¶
func (f *FakeCompiler) GetErrors() yakast.YakMergeError
func (*FakeCompiler) GetFormattedCode ¶
func (f *FakeCompiler) GetFormattedCode() string
type FakeVM ¶
type FakeVM struct {
// contains filtered or unexported fields
}
func (*FakeVM) NormalExec ¶
func (f *FakeVM) NormalExec()
type ScopeValue ¶
Source Files ¶
Click to show internal directories.
Click to hide internal directories.