Operating System
What feature would you like to be added?
Support structs as return values and parameters of functions on Windows.
Why is this needed?
Technically purego already supports structs, but you have to make some weird stunts:
If the struct's size is less than or equal 8 bytes, you just can convert them into a uintptr. Same goes for return values. Example:
C:
RLAPI void ClearBackground(Color color);
Golang:
var clearBackground func(col uintptr)
purego.RegisterLibFunc(&clearBackground, raylibDll, "ClearBackground")
func ClearBackground(col color.RGBA) {
clearBackground(*(*uintptr)(unsafe.Pointer(&col)))
}
If the struct's size is lager then 8 bytes, you have to use a pointer as parameter. For return values you have to pass it as first argument. Here is another example from raylib-go:
C:
RLAPI Texture2D LoadTextureCubemap(Image image, int layout);
Golang:
var loadTextureCubemap func(texture *Texture2D, image *Image, layout int32)
purego.RegisterLibFunc(&loadTextureCubemap, raylibDll, "LoadTextureCubemap")
func LoadTextureCubemap(image Image, layout int32) Texture2D {
var texture Texture2D
loadTextureCubemap(&texture, &image, layout)
return texture
}
Operating System
What feature would you like to be added?
Support structs as return values and parameters of functions on Windows.
Why is this needed?
Technically purego already supports structs, but you have to make some weird stunts:
If the struct's size is less than or equal 8 bytes, you just can convert them into a uintptr. Same goes for return values. Example:
C:
Golang:
If the struct's size is lager then 8 bytes, you have to use a pointer as parameter. For return values you have to pass it as first argument. Here is another example from raylib-go:
C:
Golang: