{"action":"closed","issue":{"url":"https://api.github.com/repos/bang590/JSPatch/issues/429","repository_url":"https://api.github.com/repos/bang590/JSPatch","labels_url":"https://api.github.com/repos/bang590/JSPatch/issues/429/labels{/name}","comments_url":"https://api.github.com/repos/bang590/JSPatch/issues/429/comments","events_url":"https://api.github.com/repos/bang590/JSPatch/issues/429/events","html_url":"https://github.com/bang590/JSPatch/issues/429","id":162300877,"number":429,"title":"请问调用 C 函数时如何取地址?","user":{"login":"VincentSit","id":4084679,"avatar_url":"https://avatars.githubusercontent.com/u/4084679?v=3","gravatar_id":"","url":"https://api.github.com/users/VincentSit","html_url":"https://github.com/VincentSit","followers_url":"https://api.github.com/users/VincentSit/followers","following_url":"https://api.github.com/users/VincentSit/following{/other_user}","gists_url":"https://api.github.com/users/VincentSit/gists{/gist_id}","starred_url":"https://api.github.com/users/VincentSit/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/VincentSit/subscriptions","organizations_url":"https://api.github.com/users/VincentSit/orgs","repos_url":"https://api.github.com/users/VincentSit/repos","events_url":"https://api.github.com/users/VincentSit/events{/privacy}","received_events_url":"https://api.github.com/users/VincentSit/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":2,"created_at":"2016-06-25T21:40:01Z","updated_at":"2016-06-30T02:57:01Z","closed_at":"2016-06-30T02:57:01Z","body":"@bang590  感谢你为开源界的无私奉献。我在使用中遇到了一个问题，想请教一下。\r\n\r\n我已经看了 [C 函数调用](https://github.com/bang590/JSPatch/wiki/C-%E5%87%BD%E6%95%B0%E8%B0%83%E7%94%A8) 和 [jsCFunctionTest.js](https://github.com/bang590/JSPatch/blob/091a50c8c9374951c1f31b4454a01327375217e6/Demo/iOSDemo/JSPatchTests/jsCFunctionTest.js)。\r\n\r\n也搜索了一下项目，似乎没有找到如何取地址的方式。\r\n\r\n我想在 JS 中调用这个 C 函数：\r\n```\r\n/// GLenum: unsigned int\r\n/// GLint: signed int\r\nGL_API void GL_APIENTRY glGetRenderbufferParameteriv (GLenum target, GLenum pname, GLint* params);\r\n```\r\n\r\n调用时最后一个参数需要传入一个地址，调用如下：\r\n\r\n```\r\nglGetRenderbufferParameteriv(GL_RENDERBUFFER, GL_RENDERBUFFER_HEIGHT, &_videoHeight);\r\n```\r\n\r\n我在 JS 中声明了这个函数：\r\n```\r\ndefineCFunction(\"glGetRenderbufferParameteriv\", \"void, unsigned int, unsigned int, void*\")\r\n```\r\n\r\nDemo 中都是默认把变量定义为指针类型，但是我这里的参数 `_videoHeight` 并没有声明为指针，并且在文件中多处调用了这个参数，修改它似乎更麻烦。\r\n\r\n但是 JS 是无法取地址的，有解决办法吗？\r\n\r\n------\r\n\r\n另外我对文档有点疑惑。\r\n\r\n依据你对 `defineCFunction` 接口的解释：\r\n```\r\ndefineCFunction({functionName}, {returnType & paramsType})\r\n```\r\n\r\n你在文档中对 `malloc` 的定义是:\r\n\r\n```\r\ndefineCFunction(\"malloc\", \"void *, size_t\")\r\n```\r\n它的原型是: \r\n\r\n```\r\nvoid* malloc (size_t size)\r\n```\r\n这看起来是没有错的。\r\n\r\n但是后面又举了一个例子: \r\n```\r\nint funcA(void *ptr, NSObject *obj, float num) {}\r\n```\r\n\r\n你的定义是:\r\n\r\n```\r\ndefineCFunction(\"funcA\", \"void *, NSObject *, float\")\r\n```\r\n\r\n如果按照你上面对接口的解释，是不是应该定义为：\r\n\r\n```\r\ndefineCFunction(\"funcA\", \"int, void *, NSObject *, float\")\r\n```\r\n\r\n并且下方的目前支持的参数类型中没有 `NSObject`，注意中说：\r\n\r\n> 所有的指针类型都用 void * 代替。\r\n\r\n所以这个函数最终的定义应为:\r\n\r\n```\r\ndefineCFunction(\"funcA\", \"int, void *, void *, float\")\r\n```\r\n\r\n是我理解错了吗?"}}
{"actor":{"display_login":"bang590"}}