D callbacks in C functions

I am writing `D2` bindings for Lua. This is in one of the Lua header files. typedef int (*lua_CFunction) (lua_State *L); I assume the equivalent `D2` statement would be: extern(C) alias int function( lua_State* L ) lua_CFunction; Lua also provides an api function: void lua_pushcfunction( lua_State* L, string name, lua_CFunction func ); If I want to push a `D2` function does it have to be extern(C) or can I just use the function? int dfunc( lua_State* L ) { std.stdio.writeln("dfunc"); } extern(C) int cfunc( lua_State* L ) { std.stdio.writeln("cfunc"); } lua_State* L = lua_newstate(); lua_pushcfunction(L, "cfunc", &cfunc); //This will definitely work. lua_pushcfunction(L, "dfunc", &dfunc); //Will this work? If I can only use `cfunc`, why? I don't need to do anything like that in `C++`. I can just pass the address of a `C++` function to `C` and everything just works.
There are some bindings that currently exsist, not sure how good they are: code.google.com/p/dlua

以上就是D callbacks in C functions的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » Node.js答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准