Skip to content

Commit

Permalink
fix: resolve type conversion error for C function pointers
Browse files Browse the repository at this point in the history
  • Loading branch information
dongwlin committed Aug 12, 2024
1 parent ca889c1 commit 1b53211
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions custom_sync_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,15 +117,17 @@ func (ctx SyncContext) TouchUp(contact int32) bool {
return C.MaaSyncContextTouchUp(ctx.handle, C.int32_t(contact)) != 0
}

type captureFuncType func(C.MaaSyncContextHandle, C.MaaImageBufferHandle) C.uint8_t

func (ctx SyncContext) Screencap() (image.Image, error) {
return ctx.getImage(C.MaaSyncContextScreencap)
return ctx.getImage(maaSyncContextScreencap)
}

func (ctx SyncContext) CacheImage() (image.Image, error) {
return ctx.getImage(C.MaaSyncContextCachedImage)
return ctx.getImage(maaSyncContextCachedImage)
}

func (ctx SyncContext) getImage(captureFunc func(C.MaaSyncContextHandle, C.MaaImageBufferHandle) C.int) (image.Image, error) {
func (ctx SyncContext) getImage(captureFunc captureFuncType) (image.Image, error) {
outImage := NewImageBuffer()
defer outImage.Destroy()

Expand All @@ -141,3 +143,11 @@ func (ctx SyncContext) getImage(captureFunc func(C.MaaSyncContextHandle, C.MaaIm

return img, nil
}

func maaSyncContextScreencap(handle C.MaaSyncContextHandle, imageBufferHandle C.MaaImageBufferHandle) C.uint8_t {
return C.MaaSyncContextScreencap(handle, imageBufferHandle)
}

func maaSyncContextCachedImage(handle C.MaaSyncContextHandle, imageBufferHandle C.MaaImageBufferHandle) C.uint8_t {
return C.MaaSyncContextCachedImage(handle, imageBufferHandle)
}

0 comments on commit 1b53211

Please sign in to comment.