-
Notifications
You must be signed in to change notification settings - Fork 73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can I pass NSPoint to a method? #88
Comments
This is correct. struct arguments are not supported by Send since they aren't supported by RegisterLibFunc |
For |
For the case of NSPoint that should work on amd64 (see this). As well as on amd64 (see Sec. B - 3). Ignore the fact that is a Microsoft page. Windows arm64 uses the same calling convention as macOS. Godbolt shows the same thing. Note though that doing so is flaky for anything unaligned or bigger than 16 bytes. The reason I had not added support yet is because you have to determine if it is passed in registers or as a pointer to the struct. |
Thanks! At the same time, |
Is there any new progress on this? |
There is a work around by using NSInvocation. That's what ebitengine does. However, it doesn't work on normal C functions that take or return structs. It only works on Objective-C methods |
Thanks. It looks like what I want |
Hello! This is a wonderful project. I just wanted to follow up on this thread regarding passing/returning structs, as I have a huge interest in calling functions that accept/return POD types (at least on linux and darwin). This would enable us to interface with some standard libraries we use without having to rewrite them from scratch in golang. Has there been any progress on this front, or is there a branch I can check out? |
No there hasn't been any work. If you are interested in tackling this a PR would be much appreciated. As for solutions on macOS you can use NSInvocation as was mentioned earlier. Another cross platform solution is libffi. I personally haven't used it but it should work to circumvent the lack of struct support in purego. |
Appreciate the fast response! Libffi is a neat idea. A fast alternative may also be to write wrapper functions that only use raw pointers as arguments, but, of course, that somewhat circumvents a proper solution to this struct-passing problem... |
Wrappers are another good solution. Of course adding support for structs would be the best. |
For anyone looking for an example of NSInvocation here’s one that opens a window. https://go.dev/play/p/J7nKrpnG1CH |
@TotallyGamerJet @ksil clearBackground(*(*uintptr)(unsafe.Pointer(&color.RGBA{255, 255, 255, 255}))) If the function returns a struct bigger then 64 bits, pass a reference as first argument: var texture Texture2D
loadTexture(uintptr(unsafe.Pointer(&texture)), "icon.png") |
Sure that works for some cases but wouldn't everywhere especially arm64 where a struct with all the same field types that's less than or equal to 8 bytes is put into one register in reverse order. I'm currently working on proper struct support. Arm64 is looking pretty solid. My plan is to have it done by end of next week. |
https://developer.apple.com/documentation/appkit/nscursor/1524612-initwithimage
Currently, passing a struct via Send is not supported, right?
The text was updated successfully, but these errors were encountered: