作者:手机用户2602932547 | 来源:互联网 | 2023-08-19 06:05
ImtryingtouseaClibraryinSwift,andImhavingtroublecallinganyfunctionthattakesafun
I'm trying to use a C library in Swift, and I'm having trouble calling any function that takes a function pointer as one of it's arguments. For example, part of the lua.h file that I'm trying to use in Swift looks like this:
我正在尝试在Swift中使用C库,而我在调用任何将函数指针作为其参数之一的函数时遇到了麻烦。例如,我试图在Swift中使用的lua.h文件的一部分如下所示:
LUA_API void (lua_setuservalue) (lua_State *L, int idx);
typedef int (*lua_CFunction) (lua_State *L);
LUA_API void (lua_callk) (lua_State *L, int nargs, int nresults, int ctx,
lua_CFunction k);
I use the bridging header to get access to the library, and from my Swift code I can call lua_setuservalue without any trouble. But if I try to call lua_callk I get "use of unresolved identifier 'lua_callk'". If I remove the function pointer from the declaration for lua_callk, I no longer get this error. Any help is quite appreciated.
我使用桥接头来访问库,从我的Swift代码中我可以毫无困难地调用lua_setuservalue。但是,如果我尝试调用lua_callk,我会“使用未解析的标识符'lua_callk'”。如果我从lua_callk的声明中删除函数指针,我不再收到此错误。任何帮助都非常感谢。
3 个解决方案