checker,gen: allow using methods as function pointers#14407
Merged
medvednikov merged 2 commits intomasterfrom May 15, 2022
Merged
checker,gen: allow using methods as function pointers#14407medvednikov merged 2 commits intomasterfrom
medvednikov merged 2 commits intomasterfrom
Conversation
Contributor
|
It could even run this: module main
import gg
import gx
[heap]
struct App {
mut:
gg &gg.Context = 0
radius f64 = 10.0
}
fn (mut app App) frame(x voidptr) {
// NB: here x is === voidptr(app), and gg will call the method 🎉 ...
app.gg.begin()
app.gg.draw_circle_empty(150, 150, f32(app.radius), gx.blue)
app.gg.draw_text(20, 20, 'radius: $app.radius')
app.gg.end()
}
fn main() {
mut app := &App{}
app.gg = gg.new_context(
bg_color: gx.white
width: 300
height: 300
window_title: 'Circles'
frame_fn: app.frame // passing a method as a callback works fine!
user_data: app
)
app.gg.run()
} |
vincenzopalazzo
approved these changes
May 15, 2022
Contributor
|
Fantastic! 🥳 |
larpon
approved these changes
May 15, 2022
medvednikov
approved these changes
May 15, 2022
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.