Skip to content

Instantly share code, notes, and snippets.

@dhonx
Created November 17, 2019 18:17
Show Gist options
  • Save dhonx/619a28a67d1fc26a6b17e587f973fb69 to your computer and use it in GitHub Desktop.
Save dhonx/619a28a67d1fc26a6b17e587f973fb69 to your computer and use it in GitHub Desktop.
Store function on array - V Programming Language
struct Sintf {
func fn() int
}
// Helper for calling the function
fn callf(p voidptr) int {
f := Sintf{ p }.func
return f()
}
fn main() {
afuncs := [ voidptr(test1), voidptr(test2), voidptr(test3) ]
for f in afuncs {
res := callf(f)
println(res)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment