Pass struct method as fn argument #11720
Replies: 5 comments 1 reply
-
Do give a bit of context, I am calling a C function to set a callback. type FnKey = fn (window &C.GLFWwindow, key_id, scan_code, action, bit_filed int)
fn C.glfwSetKeyCallback(window &C.GLFWwindow, callback FnKey) FnKey
struct Keyboard {
// Internal state
}
fn (k &Keyboard) update (window &C.GLFWwindow, key_id, scan_code, action, bit_filed int) {
// update keyboard internal state
}
fn update (window &C.GLFWwindow, key_id, scan_code, action, bit_filed int) {
// can't do much
}
fn main() {
k := Keyboard{}
data := C.GLFWwindow{}
C.glfwSetKeyCallback(data, update) // useless to me
C.glfwSetKeyCallback(data, k.update) // more useful
// ...
}
|
Beta Was this translation helpful? Give feedback.
-
My first question: Is it really necessary to use glfw? That was removed from V a while ago. Yes, it's still around, but... |
Beta Was this translation helpful? Give feedback.
-
If I do a wrapper around GLFW for my own purposes? :) |
Beta Was this translation helpful? Give feedback.
-
Oh, no problem if you want to use it, I was just curious. It always seemed to be problematic before. In any case, yes, it should be looked into. |
Beta Was this translation helpful? Give feedback.
-
It is my believe that this has been implemented already. Shall I close this discussion? |
Beta Was this translation helpful? Give feedback.
-
Description
In high level languages it is possible to pass a method from a class/struct as an argument
An example from C# (Unity pays my rent...):
It would be nice to have this also allowed in
Vlang
. Perhaps it is in the works, perhaps it is a bug, I am opening it as a feature nevertheless.Code
A snippet of a similar code that isn't compiling as of 0.1.29:
Error
Currently this snippet is throwing this error:
Beta Was this translation helpful? Give feedback.
All reactions