2014-07-26 3 views
5

Dlang으로 OpenGL 샘플을 실행하려고합니다.Dlang에 함수 포인터 전달

void onError(int code, const(char)* text) nothrow 
{ 
} 

사용법 :

glfwSetErrorCallback(&onError); 

바인딩 코드 :

__gshared { 

    da_glfwSetErrorCallback glfwSetErrorCallback; 

    ... 

extern(C) @ nogc nothrow { 

    alias da_glfwSetErrorCallback = GLFWerrorfun function(GLFWerrorfun); 

    ... 

    alias GLFWerrorfun = void function(int, const(char)*); 

그리고 난 다음 컴파일러 오류 얻을 :

Error: function pointer glfwSetErrorCallback (extern (C) void function(int, const(char)*) nothrow) is not callable using argument types (void function(int code, const(char)* text) nothrow) 

컴파일러 : 2.065.0

을 콜백에 interfacing to C guidelines에서 0

답변

6

:

D can easily call C callbacks (function pointers), and C can call callbacks provided by D code if the callback is an extern(C) function, or some other linkage that both sides have agreed to (e.g. extern(Windows)).

그래서 나는 당신이이 유형의 서명과 일치하기 위해서는 extern(C)로 선언하기 위해 onError 기능을 필요가 있다고 생각합니다.

+0

감사합니다. 이제 작동합니다! – Grigory