Zig 预期类型?外部fn

Zig 预期类型?外部fn,zig,Zig,我不知道C或Zig。但我正在尝试一些东西,到目前为止我真的印象深刻。我正在尝试使用C库“lwan”在Zig中运行web服务器。它起作用了。但是我在做处理函数时遇到了一些问题 /mnt/c/www/zig/hello/main.zig:35:56: error: expected type '?extern fn([*c].cimport:4:14.struct_lwan_request, [*c].cimport:4:14.struct_lwan_response, ?*c_void) .cim

我不知道C或Zig。但我正在尝试一些东西,到目前为止我真的印象深刻。我正在尝试使用C库“lwan”在Zig中运行web服务器。它起作用了。但是我在做处理函数时遇到了一些问题

/mnt/c/www/zig/hello/main.zig:35:56: error: expected type '?extern fn([*c].cimport:4:14.struct_lwan_request, [*c].cimport:4:14.struct_lwan_response, ?*c_void) .cimport:4:14.enum_lwan_http_status', found '*const fn([*c].cimport:4:14.struct_lwan_request, [*c].cimport:4:14.struct_lwan_response, ?*c_void) .cimport:4:14.enum_lwan_http_status'
        lwan.lwan_url_map{ .prefix = c"/", .handler = &hello_world },
                                                       ^
/mnt/c/www/zig/hello/main.zig:35:56: note: pointer type child 'fn([*c].cimport:4:14.struct_lwan_request, [*c].cimport:4:14.struct_lwan_response, ?*c_void) .cimport:4:14.enum_lwan_http_status' cannot cast into pointer type child '.cimport:4:14.enum_lwan_http_status'
        lwan.lwan_url_map{ .prefix = c"/", .handler = &hello_world },
                                                       ^
zig-cache/o/7Ejdc3DFhsEkPBHu2o3vlPoREApH2LmQtGmS7KyNIBhIeaHdzX6DwQhyzd5U7Eo0/cimport.zig:1234:35: note: .cimport:4:14.enum_lwan_http_status declared here
pub const enum_lwan_http_status = extern enum {
所以我猜我的处理函数的类型是错误的。这是我的处理程序:

fn hello_world(req: [*c]lwan.struct_lwan_request, res: [*c]lwan.struct_lwan_response, data: ?*c_void) lwan.enum_lwan_http_status {
    return lwan.enum_lwan_http_status.HTTP_OK;
}
如何将其更改为类型“?extern fn”

我甚至不确定我在做我应该做的事情。如果这不是Zig的目的,请告诉我

还有一件事:lwan使用以下代码创建处理程序:

#定义LWAN处理程序(名称)\
静态枚举lwan_http_状态lwan_处理程序35;#名称35;(\
结构lwan\u请求*,结构lwan\u响应*,无效*)
#定义LWAN\u处理程序\u定义(名称)\
静态常量结构lwan\u处理程序\u信息\
__属性(已使用,节(LWAN\U节名称(LWAN\U处理程序)))\
lwan_handler_info_##name_={.name=#name_\
.handler=lwan_handler_35;#name_35;\
静态枚举lwan_http_状态lwan_处理程序35;#名称35;(\
结构lwan_请求*请求_属性_((未使用))\
结构lwan_响应*响应_属性_((未使用))\
void*数据属性(未使用)
#定义LWAN\u处理程序(名称)\
LWAN_HANDLER_DECLARE(名称)\
LWAN\u处理器\u定义(名称)
然后使用它传递处理程序:

#定义LWAN处理程序(名称)LWAN处理程序(名称)_

您需要通过在处理函数前面添加单词
extern
使其具有C调用约定:

extern fn hello_world(req: [*c]lwan.struct_lwan_request, res: [*c]lwan.struct_lwan_response, data: ?*c_void) lwan.enum_lwan_http_status {
    return lwan.enum_lwan_http_status.HTTP_OK;
}
另请参阅此相关问题,这可能有助于澄清语法: