Documentation
¶
Index ¶
- Constants
- func GetAsmText(code []ByteCode, codeIndex int) string
- func RollDoubleCross(src *rand.PCGSource, addLine IntType, pool IntType, points IntType, mode int) (IntType, IntType, IntType, string)
- func RollWoD(src *rand.PCGSource, addLine IntType, pool IntType, points IntType, ...) (IntType, IntType, IntType, string)
- func ValueEqual(a *VMValue, b *VMValue, autoConvert bool) bool
- type ArrayData
- type BufferSpan
- type ByteCode
- type CodeType
- type ComputedData
- type Context
- func (ctx *Context) Depth() int
- func (ctx *Context) GetAsmText() string
- func (ctx *Context) GetCurSeed() ([]byte, error)
- func (ctx *Context) GetDetailText() string
- func (ctx *Context) GetErrorText() string
- func (ctx *Context) Init()
- func (ctx *Context) IsCalculateExists() bool
- func (ctx *Context) LoadName(name string, isRaw bool, useHook bool) *VMValue
- func (ctx *Context) LoadNameGlobal(name string, isRaw bool) *VMValue
- func (ctx *Context) LoadNameGlobalWithDetail(name string, isRaw bool, detail *BufferSpan) *VMValue
- func (ctx *Context) LoadNameLocal(name string, isRaw bool) *VMValue
- func (ctx *Context) LoadNameLocalWithDetail(name string, isRaw bool, detail *BufferSpan) *VMValue
- func (ctx *Context) LoadNameWithDetail(name string, isRaw bool, useHook bool, detail *BufferSpan) *VMValue
- func (ctx *Context) Parse(value string) error
- func (ctx *Context) RegCustomDice(s string, callback func(ctx *Context, groups []string) *VMValue) error
- func (ctx *Context) Run(value string) error
- func (ctx *Context) RunAfterParsed() error
- func (ctx *Context) RunExpr(value string, useUpCtxLocal bool) (*VMValue, error)
- func (ctx *Context) SetConfig(cfg *RollConfig)
- func (ctx *Context) StackTop() int
- func (ctx *Context) StoreName(name string, v *VMValue, useHook bool)
- func (ctx *Context) StoreNameGlobal(name string, v *VMValue)
- func (ctx *Context) StoreNameLocal(name string, v *VMValue)
- type DictData
- type FunctionData
- type IntType
- func Roll(src *rand.PCGSource, dicePoints IntType, mod int) IntType
- func RollCoC(src *rand.PCGSource, isBonus bool, diceNum IntType, mode int) (IntType, string)
- func RollCommon(src *rand.PCGSource, times, dicePoints IntType, diceMin, diceMax *IntType, ...) (IntType, string)
- func RollFate(src *rand.PCGSource, mode int) (IntType, string)
- type NativeFunctionData
- type NativeFunctionDef
- type NativeObjectData
- type ParserCustomData
- type ParserData
- func (p *ParserData) AddAttrSet(objName string, attr string, isRaw bool)
- func (p *ParserData) AddDiceDetail(begin IntType, end IntType)
- func (e *ParserData) AddFormatString(num IntType)
- func (e *ParserData) AddInvoke(paramsNum IntType)
- func (e *ParserData) AddInvokeMethod(name string, paramsNum IntType)
- func (e *ParserData) AddLoadName(value string)
- func (e *ParserData) AddOp(operator CodeType)
- func (e *ParserData) AddStModify(op string, text string)
- func (e *ParserData) AddStName()
- func (e *ParserData) AddStore(text string)
- func (p *ParserData) AddStoreComputed(name string, text string)
- func (p *ParserData) AddStoreComputedOnStack(text string)
- func (p *ParserData) AddStoreFunction(name string, paramsReversed []string, text string)
- func (e *ParserData) AddStoreGlobal(text string)
- func (e *ParserData) AddStoreLocal(text string)
- func (p *ParserData) BreakPush() error
- func (p *ParserData) BreakSet()
- func (p *ParserData) CodePop() ([]ByteCode, int, int)
- func (p *ParserData) CodePush(textPos int)
- func (p *ParserData) ContinuePush() error
- func (p *ParserData) ContinueSet(offsetB int)
- func (e *ParserData) CounterAdd(offset IntType)
- func (e *ParserData) CounterPop() IntType
- func (e *ParserData) CounterPush()
- func (e *ParserData) FlagsPop()
- func (e *ParserData) FlagsPush()
- func (e *ParserData) LoopBegin()
- func (e *ParserData) LoopEnd()
- func (e *ParserData) NamePop() string
- func (e *ParserData) NamePush(test string)
- func (e *ParserData) OffsetJmpSetX(offsetA int, offsetB int, rev bool)
- func (e *ParserData) OffsetPopAndSet()
- func (e *ParserData) OffsetPopN(num int)
- func (e *ParserData) OffsetPush()
- func (e *ParserData) PushArray(value IntType)
- func (e *ParserData) PushDict(value IntType)
- func (e *ParserData) PushFloatNumber(value string)
- func (e *ParserData) PushGlobal()
- func (e *ParserData) PushIntNumber(value string)
- func (e *ParserData) PushNull()
- func (e *ParserData) PushStr(value string)
- func (e *ParserData) PushThis()
- func (e *ParserData) WriteCode(T CodeType, value any)
- type RollConfig
- type StInfo
- type Stats
- type VMDictValue
- type VMValue
- func NewArrayVal(values ...*VMValue) *VMValue
- func NewArrayValRaw(data []*VMValue) *VMValue
- func NewComputedVal(expr string) *VMValue
- func NewComputedValRaw(computed *ComputedData) *VMValue
- func NewFloatVal(i float64) *VMValue
- func NewFunctionValRaw(computed *FunctionData) *VMValue
- func NewIntVal(i IntType) *VMValue
- func NewNativeFunctionVal(data *NativeFunctionData) *VMValue
- func NewNativeObjectVal(data *NativeObjectData) *VMValue
- func NewNullVal() *VMValue
- func NewStrVal(s string) *VMValue
- func VMValueFromJSON(data []byte) (*VMValue, error)
- func (v *VMValue) ArrayFuncKeepBase(ctx *Context, pickNum IntType, orderType int) (isAllInt bool, ret float64)
- func (v *VMValue) ArrayFuncKeepHigh(ctx *Context, pickNum IntType) (isAllInt bool, ret float64)
- func (v *VMValue) ArrayFuncKeepLow(ctx *Context, pickNum IntType) (isAllInt bool, ret float64)
- func (v *VMValue) ArrayItemGet(ctx *Context, index IntType) *VMValue
- func (v *VMValue) ArrayItemSet(ctx *Context, index IntType, val *VMValue) bool
- func (v *VMValue) ArrayRepeatTimesEx(ctx *Context, times *VMValue) *VMValue
- func (v *VMValue) AsBool() bool
- func (v *VMValue) AsDictKey() (string, error)
- func (v *VMValue) AttrGet(ctx *Context, name string) *VMValue
- func (v *VMValue) AttrSet(ctx *Context, name string, val *VMValue) *VMValue
- func (v *VMValue) Clone() *VMValue
- func (v *VMValue) ComputedExecute(ctx *Context, detail *BufferSpan) *VMValue
- func (v *VMValue) FuncInvoke(ctx *Context, params []*VMValue) *VMValue
- func (v *VMValue) FuncInvokeNative(ctx *Context, params []*VMValue) *VMValue
- func (v *VMValue) FuncInvokeRaw(ctx *Context, params []*VMValue, useUpCtxLocal bool) *VMValue
- func (v *VMValue) GetSlice(ctx *Context, a IntType, b IntType, step IntType) *VMValue
- func (v *VMValue) GetSliceEx(ctx *Context, a *VMValue, b *VMValue) *VMValue
- func (v *VMValue) GetTypeName() string
- func (v *VMValue) ItemGet(ctx *Context, index *VMValue) *VMValue
- func (v *VMValue) ItemSet(ctx *Context, index *VMValue, val *VMValue) bool
- func (v *VMValue) Length(ctx *Context) IntType
- func (v *VMValue) MustReadArray() *ArrayData
- func (v *VMValue) MustReadDictData() *DictData
- func (v *VMValue) MustReadFloat() float64
- func (v *VMValue) MustReadInt() IntType
- func (v *VMValue) OpAdd(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpBitwiseAnd(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpBitwiseOr(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpCompEQ(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpCompGE(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpCompGT(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpCompLE(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpCompLT(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpCompNE(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpDivide(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpModulus(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpMultiply(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpNegation() *VMValue
- func (v *VMValue) OpNullCoalescing(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpPositive() *VMValue
- func (v *VMValue) OpPower(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) OpSub(ctx *Context, v2 *VMValue) *VMValue
- func (v *VMValue) ReadArray() (*ArrayData, bool)
- func (v *VMValue) ReadComputed() (*ComputedData, bool)
- func (v *VMValue) ReadDictData() (*DictData, bool)
- func (v *VMValue) ReadFloat() (float64, bool)
- func (v *VMValue) ReadFunctionData() (*FunctionData, bool)
- func (v *VMValue) ReadInt() (IntType, bool)
- func (v *VMValue) ReadNativeFunctionData() (*NativeFunctionData, bool)
- func (v *VMValue) ReadNativeObjectData() (*NativeObjectData, bool)
- func (v *VMValue) ReadString() (string, bool)
- func (v *VMValue) SetSlice(ctx *Context, a, b, step IntType, val *VMValue) bool
- func (v *VMValue) SetSliceEx(ctx *Context, a *VMValue, b *VMValue, val *VMValue) bool
- func (v *VMValue) ToJSON() ([]byte, error)
- func (v *VMValue) ToJSONRaw(save map[*VMValue]bool) ([]byte, error)
- func (v *VMValue) ToRepr() string
- func (v *VMValue) ToString() string
- func (v *VMValue) UnmarshalJSON(input []byte) error
- type VMValueType
- type ValueMap
- func (m *ValueMap) Clear()
- func (m *ValueMap) Delete(key string)
- func (m *ValueMap) Length() int
- func (m *ValueMap) Load(key string) (value *VMValue, ok bool)
- func (m *ValueMap) LoadAndDelete(key string) (value *VMValue, loaded bool)
- func (m *ValueMap) LoadOrStore(key string, value *VMValue) (actual *VMValue, loaded bool)
- func (m *ValueMap) MustLoad(key string) *VMValue
- func (m *ValueMap) Range(f func(key string, value *VMValue) bool)
- func (m *ValueMap) Store(key string, value *VMValue)
- func (m *ValueMap) ToJSON() ([]byte, error)
- func (m *ValueMap) UnmarshalJSON(input []byte) error
Constants ¶
const IntTypeSize = strconv.IntSize / 8 // 只能为 4 或 8(32位/64位)
Variables ¶
This section is empty.
Functions ¶
func GetAsmText ¶
func RollDoubleCross ¶
Types ¶
type BufferSpan ¶
type ByteCode ¶
func (*ByteCode) CodeString ¶
type ComputedData ¶
type Context ¶
type Context struct { Attrs *ValueMap UpCtx *Context NumOpCount IntType // 算力计数 Config RollConfig // 标记 Error error // 报错信息 Ret *VMValue // 返回值 RestInput string // 剩余字符串 Matched string // 匹配的字符串 DetailSpans []BufferSpan IsComputedLoaded bool Seed []byte // 随机种子,16个字节,即双uint64 RandSrc *rand.PCGSource // 根据种子生成的source IsRunning bool // 是否正在运行,Run时会置为true,halt时会置为false CustomDiceInfo []*customDiceItem // 全局scope的写入回调 GlobalValueStoreFunc func(name string, v *VMValue) // 全局scope的读取回调 GlobalValueLoadFunc func(name string) *VMValue // 全局scope的读取后回调(返回值将覆盖之前读到的值。如果之前未读取到值curVal将为nil) GlobalValueLoadOverwriteFunc func(name string, curVal *VMValue) *VMValue // contains filtered or unexported fields }
func (*Context) GetAsmText ¶
func (*Context) GetCurSeed ¶
func (*Context) GetDetailText ¶
func (*Context) GetErrorText ¶
GetErrorText 主要用于js,因为ctx.Error是数组,在js那边不被当做正常的异常对象,所以会报错
func (*Context) IsCalculateExists ¶
IsCalculateExists 只有表达式被解析后,才能被调用,暂不考虑存在invoke指令的情况
func (*Context) LoadNameGlobal ¶
func (*Context) LoadNameGlobalWithDetail ¶
func (ctx *Context) LoadNameGlobalWithDetail(name string, isRaw bool, detail *BufferSpan) *VMValue
func (*Context) LoadNameLocalWithDetail ¶
func (ctx *Context) LoadNameLocalWithDetail(name string, isRaw bool, detail *BufferSpan) *VMValue
func (*Context) LoadNameWithDetail ¶
func (*Context) RegCustomDice ¶
func (*Context) RunAfterParsed ¶
func (*Context) SetConfig ¶
func (ctx *Context) SetConfig(cfg *RollConfig)
func (*Context) StoreNameGlobal ¶
func (*Context) StoreNameLocal ¶
type FunctionData ¶
type IntType ¶
type IntType int // :IntType
type NativeFunctionData ¶
type NativeFunctionData struct { Name string Params []string Defaults []*VMValue /* 缓存数据 */ Self *VMValue // 若存在self,即为bound method NativeFunc NativeFunctionDef }
type NativeFunctionDef ¶
type NativeObjectData ¶
type NativeObjectData struct { Name string AttrSet func(ctx *Context, name string, v *VMValue) AttrGet func(ctx *Context, name string) *VMValue ItemSet func(ctx *Context, index *VMValue, v *VMValue) ItemGet func(ctx *Context, index *VMValue) *VMValue DirFunc func(ctx *Context) []*VMValue ToString func(ctx *Context) string }
type ParserCustomData ¶
type ParserCustomData struct {
ParserData
}
type ParserData ¶
type ParserData struct { Config RollConfig // contains filtered or unexported fields }
func (*ParserData) AddAttrSet ¶
func (p *ParserData) AddAttrSet(objName string, attr string, isRaw bool)
func (*ParserData) AddDiceDetail ¶
func (p *ParserData) AddDiceDetail(begin IntType, end IntType)
func (*ParserData) AddFormatString ¶
func (e *ParserData) AddFormatString(num IntType)
func (*ParserData) AddInvoke ¶
func (e *ParserData) AddInvoke(paramsNum IntType)
func (*ParserData) AddInvokeMethod ¶
func (e *ParserData) AddInvokeMethod(name string, paramsNum IntType)
func (*ParserData) AddLoadName ¶
func (e *ParserData) AddLoadName(value string)
func (*ParserData) AddOp ¶
func (e *ParserData) AddOp(operator CodeType)
func (*ParserData) AddStModify ¶
func (e *ParserData) AddStModify(op string, text string)
func (*ParserData) AddStName ¶
func (e *ParserData) AddStName()
func (*ParserData) AddStore ¶
func (e *ParserData) AddStore(text string)
func (*ParserData) AddStoreComputed ¶
func (p *ParserData) AddStoreComputed(name string, text string)
func (*ParserData) AddStoreComputedOnStack ¶
func (p *ParserData) AddStoreComputedOnStack(text string)
func (*ParserData) AddStoreFunction ¶
func (p *ParserData) AddStoreFunction(name string, paramsReversed []string, text string)
func (*ParserData) AddStoreGlobal ¶
func (e *ParserData) AddStoreGlobal(text string)
func (*ParserData) AddStoreLocal ¶
func (e *ParserData) AddStoreLocal(text string)
func (*ParserData) BreakPush ¶
func (p *ParserData) BreakPush() error
func (*ParserData) BreakSet ¶
func (p *ParserData) BreakSet()
func (*ParserData) CodePush ¶
func (p *ParserData) CodePush(textPos int)
func (*ParserData) ContinuePush ¶
func (p *ParserData) ContinuePush() error
func (*ParserData) ContinueSet ¶
func (p *ParserData) ContinueSet(offsetB int)
func (*ParserData) CounterAdd ¶
func (e *ParserData) CounterAdd(offset IntType)
func (*ParserData) CounterPop ¶
func (e *ParserData) CounterPop() IntType
func (*ParserData) CounterPush ¶
func (e *ParserData) CounterPush()
func (*ParserData) FlagsPop ¶
func (e *ParserData) FlagsPop()
func (*ParserData) FlagsPush ¶
func (e *ParserData) FlagsPush()
func (*ParserData) LoopBegin ¶
func (e *ParserData) LoopBegin()
func (*ParserData) LoopEnd ¶
func (e *ParserData) LoopEnd()
func (*ParserData) NamePop ¶
func (e *ParserData) NamePop() string
func (*ParserData) NamePush ¶
func (e *ParserData) NamePush(test string)
func (*ParserData) OffsetJmpSetX ¶
func (e *ParserData) OffsetJmpSetX(offsetA int, offsetB int, rev bool)
func (*ParserData) OffsetPopAndSet ¶
func (e *ParserData) OffsetPopAndSet()
func (*ParserData) OffsetPopN ¶
func (e *ParserData) OffsetPopN(num int)
func (*ParserData) OffsetPush ¶
func (e *ParserData) OffsetPush()
func (*ParserData) PushArray ¶
func (e *ParserData) PushArray(value IntType)
func (*ParserData) PushDict ¶
func (e *ParserData) PushDict(value IntType)
func (*ParserData) PushFloatNumber ¶
func (e *ParserData) PushFloatNumber(value string)
func (*ParserData) PushGlobal ¶
func (e *ParserData) PushGlobal()
func (*ParserData) PushIntNumber ¶
func (e *ParserData) PushIntNumber(value string)
func (*ParserData) PushNull ¶
func (e *ParserData) PushNull()
func (*ParserData) PushStr ¶
func (e *ParserData) PushStr(value string)
func (*ParserData) PushThis ¶
func (e *ParserData) PushThis()
func (*ParserData) WriteCode ¶
func (e *ParserData) WriteCode(T CodeType, value any)
type RollConfig ¶
type RollConfig struct { EnableDiceWoD bool // 启用WOD骰子语法,即XaYmZkNqM,X个数,Y加骰线,Z面数,N阈值(>=),M阈值(<=) EnableDiceCoC bool // 启用COC骰子语法,即bX/pX奖惩骰 EnableDiceFate bool // 启用Fate骰语法,即fX EnableDiceDoubleCross bool // 启用双十字骰语法,即XcY DisableBitwiseOp bool // 禁用位运算,用于st,如 &a=1d4 DisableStmts bool // 禁用语句语法(如if while等),仅允许表达式 DisableNDice bool // 禁用Nd语法,即只能2d6这样写,不能写2d // 如果返回值为true,那么跳过剩下的储存流程。如果overwrite不为nil,对v进行覆盖。 // 另注: 钩子函数中含有ctx的原因是可能在函数中进行调用,此时ctx会发生变化 HookFuncValueStore func(ctx *Context, name string, v *VMValue) (overwrite *VMValue, solved bool) // 如果overwrite不为nil,将结束值加载并使用overwrite值。如果为nil,将以newName为key进行加载 HookFuncValueLoad func(ctx *Context, name string) (newName string, overwrite *VMValue) // 读取后回调(返回值将覆盖之前读到的值。如果之前未读取到值curVal将为nil),用户需要在里面调用doCompute保证结果正确 HookFuncValueLoadOverwrite func(ctx *Context, name string, curVal *VMValue, doCompute func(curVal *VMValue) *VMValue, detail *BufferSpan) *VMValue // st回调,注意val和extra都经过clone,可以放心储存 CallbackSt func(_type string, name string, val *VMValue, extra *VMValue, op string, detail string) // st回调 CustomMakeDetailFunc func(ctx *Context, details []BufferSpan, dataBuffer []byte) string // 自定义计算过程 ParseExprLimit uint64 // 解析算力限制,防止构造特殊语句进行DOS攻击,0为无限,建议值1000万 OpCountLimit IntType // 算力限制,超过这个值会报错,0为无限,建议值30000 DefaultDiceSideExpr string // 默认骰子面数 PrintBytecode bool // 执行时打印字节码 IgnoreDiv0 bool // 当div0时暂不报错 DiceMinMode bool // 骰子以最小值结算,用于获取下界 DiceMaxMode bool // 以最大值结算 获取上界 // contains filtered or unexported fields }
type Stats ¶
type Stats struct { // ExprCnt counts the number of expressions processed during parsing // This value is compared to the maximum number of expressions allowed // (set by the MaxExpressions option). ExprCnt uint64 // ChoiceAltCnt is used to count for each ordered choice expression, // which alternative is used how may times. // These numbers allow to optimize the order of the ordered choice expression // to increase the performance of the parser // // The outer key of ChoiceAltCnt is composed of the exprType of the rule as well // as the line and the column of the ordered choice. // The inner key of ChoiceAltCnt is the number (one-based) of the matching alternative. // For each alternative the number of matches are counted. If an ordered choice does not // match, a special counter is incremented. The exprType of this counter is set with // the parser option Statistics. // For an alternative to be included in ChoiceAltCnt, it has to match at least once. ChoiceAltCnt map[string]map[string]int }
Stats stores some statistics, gathered during parsing
type VMDictValue ¶
type VMDictValue VMValue
func NewDictVal ¶
func NewDictVal(data *ValueMap) *VMDictValue
func NewDictValWithArray ¶
func NewDictValWithArray(arr ...*VMValue) (*VMDictValue, error)
func NewDictValWithArrayMust ¶
func NewDictValWithArrayMust(arr ...*VMValue) *VMDictValue
func (*VMDictValue) Load ¶
func (d *VMDictValue) Load(key string) (value *VMValue, ok bool)
Load value为变量的值,ok代表是否找到变量
func (*VMDictValue) Range ¶
func (d *VMDictValue) Range(callback func(key string, value *VMValue) bool)
func (*VMDictValue) Store ¶
func (d *VMDictValue) Store(key string, value *VMValue)
func (*VMDictValue) ToString ¶
func (d *VMDictValue) ToString() string
func (*VMDictValue) V ¶
func (d *VMDictValue) V() *VMValue
type VMValue ¶
type VMValue struct { TypeId VMValueType `json:"t"` Value any `json:"v"` }
func NewArrayVal ¶
func NewArrayValRaw ¶
func NewComputedVal ¶
func NewComputedValRaw ¶
func NewComputedValRaw(computed *ComputedData) *VMValue
func NewFloatVal ¶
func NewFunctionValRaw ¶
func NewFunctionValRaw(computed *FunctionData) *VMValue
func NewNativeFunctionVal ¶
func NewNativeFunctionVal(data *NativeFunctionData) *VMValue
func NewNativeObjectVal ¶
func NewNativeObjectVal(data *NativeObjectData) *VMValue
func NewNullVal ¶
func NewNullVal() *VMValue
func VMValueFromJSON ¶
func (*VMValue) ArrayFuncKeepBase ¶
func (*VMValue) ArrayFuncKeepHigh ¶
func (*VMValue) ArrayFuncKeepLow ¶
func (*VMValue) ArrayItemSet ¶
func (*VMValue) ArrayRepeatTimesEx ¶
func (*VMValue) ComputedExecute ¶
func (v *VMValue) ComputedExecute(ctx *Context, detail *BufferSpan) *VMValue
func (*VMValue) FuncInvokeNative ¶
func (*VMValue) FuncInvokeRaw ¶
func (*VMValue) GetSliceEx ¶
func (*VMValue) GetTypeName ¶
func (*VMValue) MustReadArray ¶
func (*VMValue) MustReadDictData ¶
func (*VMValue) MustReadFloat ¶
func (*VMValue) MustReadInt ¶
func (*VMValue) OpNegation ¶
func (*VMValue) OpNullCoalescing ¶
func (*VMValue) OpPositive ¶
func (*VMValue) ReadComputed ¶
func (v *VMValue) ReadComputed() (*ComputedData, bool)
func (*VMValue) ReadDictData ¶
func (*VMValue) ReadFunctionData ¶
func (v *VMValue) ReadFunctionData() (*FunctionData, bool)
func (*VMValue) ReadNativeFunctionData ¶
func (v *VMValue) ReadNativeFunctionData() (*NativeFunctionData, bool)
func (*VMValue) ReadNativeObjectData ¶
func (v *VMValue) ReadNativeObjectData() (*NativeObjectData, bool)
func (*VMValue) ReadString ¶
func (*VMValue) SetSliceEx ¶
func (*VMValue) UnmarshalJSON ¶
type VMValueType ¶
type VMValueType int
const ( VMTypeInt VMValueType = 0 VMTypeFloat VMValueType = 1 VMTypeString VMValueType = 2 VMTypeNull VMValueType = 4 VMTypeComputedValue VMValueType = 5 VMTypeArray VMValueType = 6 VMTypeDict VMValueType = 7 VMTypeFunction VMValueType = 8 VMTypeNativeFunction VMValueType = 9 VMTypeNativeObject VMValueType = 10 )
type ValueMap ¶
type ValueMap struct {
// contains filtered or unexported fields
}
Map is like a Go map[interface{}]interface{} but is safe for concurrent use by multiple goroutines without additional locking or coordination. Loads, stores, and deletes run in amortized constant time.
The Map type is specialized. Most code should use a plain Go map instead, with separate locking or coordination, for better type safety and to make it easier to maintain other invariants along with the map content.
The Map type is optimized for two common use cases: (1) when the entry for a given key is only ever written once but read many times, as in caches that only grow, or (2) when multiple goroutines read, write, and overwrite entries for disjoint sets of keys. In these two cases, use of a Map may significantly reduce lock contention compared to a Go map paired with a separate Mutex or RWMutex.
The zero Map is empty and ready for use. A Map must not be copied after first use.
func (*ValueMap) Load ¶
Load returns the value stored in the map for a key, or nil if no value is present. The ok result indicates whether value was found in the map.
func (*ValueMap) LoadAndDelete ¶
LoadAndDelete deletes the value for a key, returning the previous value if any. The loaded result reports whether the key was present.
func (*ValueMap) LoadOrStore ¶
LoadOrStore returns the existing value for the key if present. Otherwise, it stores and returns the given value. The loaded result is true if the value was loaded, false if stored.
func (*ValueMap) Range ¶
Range calls f sequentially for each key and value present in the map. If f returns false, range stops the iteration.
Range does not necessarily correspond to any consistent snapshot of the Map's contents: no key will be visited more than once, but if the value for any key is stored or deleted concurrently (including by f), Range may reflect any mapping for that key from any point during the Range call. Range does not block other methods on the receiver; even f itself may call any method on m.
Range may be O(N) with the number of elements in the map even if f returns false after a constant number of calls.