Skip to content

Commit

Permalink
imp: 调整了 ctx.CustomMakeDetailFunc 回调的参数
Browse files Browse the repository at this point in the history
  • Loading branch information
fy0 committed Sep 27, 2024
1 parent b06b5f3 commit 65269b7
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions rollvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ func (ctx *Context) GetErrorText() string {
return ""
}

func (ctx *Context) GetParsedOffset() int {
return ctx.parser.pt.offset
}

func (ctx *Context) Parse(value string) error {
// 检测是否正在执行,正在执行则使用新的上下文
if ctx.IsRunning {
Expand Down Expand Up @@ -189,10 +193,10 @@ d10=10[d10=10=10]=10 首先进行一次省略,即文本标注如果等于值
同理还有 [2d1,2].kl() 这个与上面等价,只是写法不同
*/
func (ctx *Context) makeDetailStr(details []BufferSpan) string {
offset := ctx.parser.pt.offset
if ctx.Config.CustomMakeDetailFunc != nil {
return ctx.Config.CustomMakeDetailFunc(ctx, details, ctx.parser.data)
return ctx.Config.CustomMakeDetailFunc(ctx, details, ctx.parser.data, offset)
}
offset := ctx.parser.pt.offset
detailResult := ctx.parser.data[:offset]

curPoint := IntType(-1) // nolint
Expand Down
2 changes: 1 addition & 1 deletion types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ type RollConfig struct {

// 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 // 自定义计算过程
CustomMakeDetailFunc func(ctx *Context, details []BufferSpan, dataBuffer []byte, parsedOffset int) string // 自定义计算过程

ParseExprLimit uint64 // 解析算力限制,防止构造特殊语句进行DOS攻击,0为无限,建议值1000万
OpCountLimit IntType // 算力限制,超过这个值会报错,0为无限,建议值30000
Expand Down

0 comments on commit 65269b7

Please sign in to comment.