Skip to content

Commit

Permalink
feat: 增加一个值读取的钩子
Browse files Browse the repository at this point in the history
  • Loading branch information
fy0 committed Jun 17, 2024
1 parent 047f070 commit 5e2a6f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions rollvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ func (ctx *Context) evaluate() {
details[len(details)-1].Ret = val
details[len(details)-1].Text = ""
}
if ctx.Config.HookFuncValueLoadOverwrite != nil {
val = ctx.Config.HookFuncValueLoadOverwrite(name, val, &details[len(details)-1])
}
stackPush(val)

case typeStoreName:
Expand Down
2 changes: 2 additions & 0 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ type RollConfig struct {
HookFuncValueStore func(ctx *Context, name string, v *VMValue) (overwrite *VMValue, solved bool)
// 如果overwrite不为nil,将结束值加载并使用overwrite值。如果为nil,将以newName为key进行加载
HookFuncValueLoad func(name string) (newName string, overwrite *VMValue)
// 读取后回调(返回值将覆盖之前读到的值。如果之前未读取到值curVal将为nil)
HookFuncValueLoadOverwrite func(name string, curVal *VMValue, detail *BufferSpan) *VMValue

CallbackSt func(_type string, name string, val *VMValue, extra *VMValue, op string, detail string) // st回调
CustomMakeDetailFunc func(ctx *Context, details []BufferSpan, dataBuffer []byte) string // 自定义计算过程
Expand Down

0 comments on commit 5e2a6f9

Please sign in to comment.