{"action":"opened","issue":{"url":"https://api.github.com/repos/node-ffi/node-ffi/issues/246","labels_url":"https://api.github.com/repos/node-ffi/node-ffi/issues/246/labels{/name}","comments_url":"https://api.github.com/repos/node-ffi/node-ffi/issues/246/comments","events_url":"https://api.github.com/repos/node-ffi/node-ffi/issues/246/events","html_url":"https://github.com/node-ffi/node-ffi/issues/246","id":107967703,"number":246,"title":"How To: Callbacks and Proper Parameter Passing","user":{"login":"tysenmoore-xse","id":1681769,"avatar_url":"https://avatars.githubusercontent.com/u/1681769?v=3","gravatar_id":"","url":"https://api.github.com/users/tysenmoore-xse","html_url":"https://github.com/tysenmoore-xse","followers_url":"https://api.github.com/users/tysenmoore-xse/followers","following_url":"https://api.github.com/users/tysenmoore-xse/following{/other_user}","gists_url":"https://api.github.com/users/tysenmoore-xse/gists{/gist_id}","starred_url":"https://api.github.com/users/tysenmoore-xse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tysenmoore-xse/subscriptions","organizations_url":"https://api.github.com/users/tysenmoore-xse/orgs","repos_url":"https://api.github.com/users/tysenmoore-xse/repos","events_url":"https://api.github.com/users/tysenmoore-xse/events{/privacy}","received_events_url":"https://api.github.com/users/tysenmoore-xse/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-09-23T17:28:05Z","updated_at":"2015-09-23T17:28:05Z","closed_at":null,"body":"I apologize up front, I am still new to web programming but I have a few questions regarding the proper use of callbacks and passing of correct data types when the interface using `void*` within ffi.\r\n\r\nI ran a simple example opening libc and got strlen and stcmp to work fine.  I wanted to extend my understanding to something more challenging that contained `void*` and callbacks.  I chose to test `qsort` from libc.  I tried a number of things and looked all over trying to piece together the correct solution but I can't get the right combination.  Some syntax I found for ffi/ref examples may be out of date or not (pointer, etc), so I'm not clear what a working solution would look like.  Any help/suggestions would be MUCH appreciated.\r\n\r\n       var ffi   = require('ffi');\r\n       var ref   = require('ref');\r\n       var array = require('ref-array');\r\n\r\n       var libName = \"/lib/x86_64-linux-gnu/libc.so.6\";\r\n\r\n       // This works fine...\r\n       var libc = ffi.Library( libName, { 'strlen': ['size_t',['string']],\r\n                                          'strcmp': ['int',['string', 'string']] });\r\n\r\n        var lstData  = ['l','m','e'];\r\n        var strArray = array('string', 3);\r\n        var lst = new strArray( lstData );\r\n\r\n        var qsortCompare = ffi.Callback('int', ['string', 'string'], \r\n                                        function(p1,p2) {\r\n                                console.log(\"   >>>> \"+p1+\" ? \"+p2);\r\n                                return libc.strcmp(p1,p2);  // previously loaded strcmp for testing purposes\r\n                                });\r\n\r\n        var libcq = ffi.Library( libName, { 'qsort': ['void',[strArray,'size_t','size_t',qsortCompare]] });\r\n\r\n        console.log(\"PRE-SORT: \"+lst);\r\n        libcq.qsort( lst, lst.length, 4, qsortCompare ); // 4 == sizeof(char*)?\r\n        console.log(\"POST-SORT: \"+lst);\r\n\r\nFor quick reference, the qsort interface looks like this:\r\n\r\n        void qsort(void *base, \r\n                  size_t nmemb, \r\n                  size_t size,\r\n                   int (*compar)(const void *, const void *));\r\n\r\nWhen I run it I get:\r\n\r\n    \"AssertionError: could not determine a proper \"type\" from: {\"type\":\"Buffer\",\"data\":[73,187,254,107,156,121,2,127]}\r\n\r\nFrom what I can tell it is not happy with the first parameter `strArray`, but I could be wrong about that as well."}}