-
Notifications
You must be signed in to change notification settings - Fork 2
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
sdl: add autogenerated methods using genmethods tool #5
base: main
Are you sure you want to change the base?
Conversation
To generate the # install genmethods tool
go install github.com/mewspring/genmethods@master
# navigate to purego-sdl3 repository
cd /path/to/purego-sdl3
# generate methods.go source file
genmethods > sdl/methods.go The genmethods tool can be updated, once we decide what methods names should be simplified (e.g. From https://github.com/mewspring/genmethods/blob/2173b27db50e61e30d7ae5bbb33d9bf4419a308b/main.go#L202: var renameMethod = map[string]string{
// Renderer methods
"DestroyRenderer": "Destroy",
"RenderClear": "Clear",
"RenderPresent": "Present",
"SetRenderDrawColor": "SetDrawColor",
// Surface methods
"BlitSurface": "Blit",
"DestroySurface": "Destroy",
"LockSurface": "Lock",
"UnlockSurface": "Unlock",
// Texture methods
"DestroyTexture": "Destroy",
// Window methods
"DestroyWindow": "Destroy",
"GetWindowSurface": "GetSurface",
"HideWindow": "Hide",
"ShowWindow": "Show",
"UpdateWindowSurface": "UpdateSurface",
} |
Just for reference, and to keep it all in once place, adding comments from #3 (comment):
|
@mewmew Thank you very much! I think having a extra file for methods is a really clean idea. I'll keep this PR open, so other people have the chance to tell their opinion too. |
This looks like a good way to do this while keeping maintenance requirements lower to me. |
The genmethods tool has now been updated (mewspring/genmethods@024577d) to add comments for the generated methods. See 844a4f7 for example output. |
Happy we found a good approach that still keeps maintenance low : ) @JupiterRider, are we ready to merge this? Hehe, at least @clseibold also agree that this looks like a good approach. Once this PR is merged, I'll be able to switch over to purego-sdl3 for my personal use : ) Exciting times to come! |
The genmethods tool is available at https://github.com/mewspring/genmethods
A Also, methods for the |
@mewmew What are the benefits of having methods? Usually they only make sense when you implement interfaces or using encapsulation. purego-sdl3 is a binding and not an abstraction layer. |
@JupiterRider These aren't real "methods" in the traditional OOP sense. But anyways, one could say it's more idiomatic to Golang to use them. It also fits along nicely with every other golang library that uses "methods". I don't think generating methods like this is much of an abstraction, and of course bindings can also be "abstraction layers" if one desires them to be. The only restriction is what you choose to place on it. |
I personally think it simplifies the API. When you have a f, err := os.Open("foo.txt")
if err { ... }
defer f.Close()
// instead of:
// defer os.CloseFile(f) But I realize that it comes down to personal preference. So, if you prefer not to have methods, that's fine. At least with I can also be convinced otherwise, that having more than one way to interact with the library is distracting, and it's better to just provide a single way. |
I personally also prefer this approach (it's a personal preference still). but some of the benefits that I expect:
|
The genmethods tool is available at https://github.com/mewspring/genmethods
Also, update examples to use methods.