1
我目前正在綁定GLFW3庫(由於各種原因,我沒有使用廢棄)的過程。這是很容易的做,不構成實際問題,以下情況除外:將C風格的回調設置函數綁定到D
extern (C) {
alias void(*GLFWwindowposfun)(GLFWwindow*, int, int);
alias void(*GLFWwindowsizefun)(GLFWwindow*, int, int);
alias void(*GLFWwindowclosefun)(GLFWwindow*);
alias void(*GLFWwindowrefreshfun)(GLFWwindow*);
alias void(*GLFWwindowfocusfun)(GLFWwindow*, int);
alias void(*GLFWwindowiconifyfun)(GLFWwindow*, int);
alias void(*GLFWframebuffersizefun)(GLFWwindow*, int, int);
}
下面是原來的聲明之一(GLFW/GLFW3.h)的定義是:
typedef void (* GLFWwindowposfun)(GLFWwindow*,int,int);
這工作不夠好,在這個意義上它編譯,但是,它觸發了以下警告:
Source/MageLib/GLFW3.di(9): Deprecation: C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers
Source/MageLib/GLFW3.di(10): Deprecation: C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers
Source/MageLib/GLFW3.di(11): Deprecation: C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers
Source/MageLib/GLFW3.di(12): Deprecation: C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers
Source/MageLib/GLFW3.di(13): Deprecation: C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers
Source/MageLib/GLFW3.di(14): Deprecation: C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers
Source/MageLib/GLFW3.di(15): Deprecation: C-style function pointer and pointer to array syntax is deprecated. Use 'function' to declare function pointers
谷歌搜索的有點讓我以下資源:http://dlang.org/function.html#closures
我不知道如何申請,雖然這一點,我已經試過這樣做,但是這顯然是行不通的:
alias void function(GLFWwindow*, int, int);
這提供了以下錯誤:
Source/MageLib/GLFW3.di(9): Error: no identifier for declarator extern (C) void function(GLFWwindow*, int, int)
我如何正確地轉換它,正確的方法?
啊!我覺得它會是這樣的,我忘了回電是D級的一等公民。謝謝。 –