在尝试包装接受回调的 C 函数时,我遇到了成员函数被视为委托的问题。C 函数不会接受委托,所以我选择了其他东西:
extern(C) void onMouse(void delegate(int, int, int) nothrow callback)
{
glfwSetMouseButtonCallback(handle,
function void (GLFWwindow* h, int button, int action, int mods) nothrow
{
callback(button, action, mods);
}
);
}
如您所见,我向回调设置函数传递了一个调用委托的函数文字(这将是我在此处传递的成员函数)。
但是,它并没有像我预期的那样结束:
Error: function pointer glfwSetMouseButtonCallback (GLFWwindow*, extern (C) void function(GLFWwindow*, int, int, int) nothrow) is not callable using argument types (GLFWwindow*, void delegate(GLFWwindow* h, int button, int action, int mods) nothrow @system)
在错误中,它显示第二个参数为 type void delegate
。
所以。我的问题是:为什么会发生这种情况?正如你可以清楚地看到的,它function void
在代码中说。
注意:我已经看到了:将代表传递给 D 中的外部 C 函数。解决方案显然是一个黑客。但是,如果我在互联网上找不到解决方法,我会尝试一下。