Skip to content

Commit

Permalink
feat(context): add api ExposeCaller
Browse files Browse the repository at this point in the history
  • Loading branch information
fumiama committed Oct 9, 2023
1 parent 3023a1d commit 57f71b9
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"reflect"
"sync"
"unsafe"

"github.com/wdvxdr1123/ZeroBot/message"
)
Expand All @@ -26,6 +27,11 @@ func (ctx *Ctx) GetMatcher() *Matcher {
return ctx.ma
}

// ExposeCaller as *T, maybe panic if misused
func ExposeCaller[T any](ctx *Ctx) *T {
return (*T)(*(*unsafe.Pointer)(unsafe.Add(unsafe.Pointer(&ctx.caller), unsafe.Sizeof(uintptr(0)))))
}

// decoder 反射获取的数据
type decoder []dec

Expand Down

0 comments on commit 57f71b9

Please sign in to comment.