TooTallNate / ref

Turn Buffer instances into "pointers"
http://tootallnate.github.com/ref
454 stars 142 forks source link

Something weird is happening with ffi, ref and ref-array. #26

Closed kalppi closed 8 years ago

kalppi commented 9 years ago

I'm trying to use libvoikko using ffi, ref and ref array modules. But I can't seem to access return value from the library, unless I'm doing something that really shouldn't affect anyhing.

var ffi = require('ffi');
var ref = require('ref');
var ArrayType = require('ref-array');

var StringArray = ArrayType('string');
var PointerArray = ArrayType('pointer');

var voikko = ffi.Library('libvoikko.so', {
    'voikkoInit': ['pointer', ['pointer', 'string', 'string']],
    'voikkoAnalyzeWordCstr': ['pointer', ['pointer', 'string']]
});

var outError = ref.alloc('string');
var handle = voikko.voikkoInit(outError, 'fi_FI', null);

var rtn = PointerArray.untilZeros(voikko.voikkoAnalyzeWordCstr(handle, 'kissa'));

//undefined
console.log(rtn[0]);

StringArray.untilZeros(new Buffer(1));

//<SlowBuffer>
console.log(rtn[0]);
TooTallNate commented 9 years ago

Can you show me some example C code of what you're trying to do?

TooTallNate commented 8 years ago

No reply, closing.