簡體   English   中英

將C風格的回調設置功能綁定到D.

[英]Binding C-style callback setting functions to D

我目前正在綁定GLFW3庫(由於各種原因,我沒有使用Derelict)。 除了以下內容之外,這很容易做到並且沒有任何實際問題:

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)

我如何正確地轉換這個,正確的方法?

別名GLFWwindowposfun = void function(GLFWwindow *,int,int);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM