implement va_list for tracelog callbacks in purego
This commit is contained in:
parent
6fd7907d31
commit
fa7e76c6a6
1 changed files with 18 additions and 1 deletions
|
@ -5,6 +5,7 @@ package rl
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"syscall"
|
||||||
"unsafe"
|
"unsafe"
|
||||||
|
|
||||||
"github.com/ebitengine/purego"
|
"github.com/ebitengine/purego"
|
||||||
|
@ -16,6 +17,15 @@ const (
|
||||||
requiredVersion = "5.0"
|
requiredVersion = "5.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var wvsprintfA uintptr
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
handle, err := windows.LoadLibrary("user32.dll")
|
||||||
|
if err == nil {
|
||||||
|
wvsprintfA, _ = windows.GetProcAddress(handle, "wvsprintfA")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// loadLibrary loads the raylib dll and panics on error
|
// loadLibrary loads the raylib dll and panics on error
|
||||||
func loadLibrary() uintptr {
|
func loadLibrary() uintptr {
|
||||||
handle, err := windows.LoadLibrary(libname)
|
handle, err := windows.LoadLibrary(libname)
|
||||||
|
@ -37,7 +47,14 @@ func loadLibrary() uintptr {
|
||||||
}
|
}
|
||||||
|
|
||||||
func traceLogCallbackWrapper(fn TraceLogCallbackFun) uintptr {
|
func traceLogCallbackWrapper(fn TraceLogCallbackFun) uintptr {
|
||||||
return purego.NewCallback(func(logLevel int32, text *byte) uintptr {
|
return purego.NewCallback(func(logLevel int32, text *byte, args unsafe.Pointer) uintptr {
|
||||||
|
if wvsprintfA != 0 {
|
||||||
|
var buffer [1024]byte // Max size is 1024 (see https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-wvsprintfa)
|
||||||
|
_, _, errno := syscall.SyscallN(wvsprintfA, uintptr(unsafe.Pointer(&buffer[0])), uintptr(unsafe.Pointer(text)), uintptr(args))
|
||||||
|
if errno == 0 {
|
||||||
|
text = &buffer[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
fn(int(logLevel), windows.BytePtrToString(text))
|
fn(int(logLevel), windows.BytePtrToString(text))
|
||||||
return 0
|
return 0
|
||||||
})
|
})
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue