lib/core.js
function createUnwrapperFunction (funcPtr, type, isVariadic) {
  var rtnType = type.retval || type[0] || 'v';
  var argTypes = type.args || type[1] || [];
  var unwrapper;

  if (isVariadic) {
    var func = ffi.VariadicForeignFunction(funcPtr, types.map(rtnType), types.mapArray(argTypes));
    unwrapper = function() {
      var newtypes = [];
      // Detect the types coming in, make sure to ignore previously defined baseTypes,
      // garner a list of these then send the function through the normal exec.
      // The types system in objc, should probably be cleaned up considerably. This is
      // somewhat faulty but since 95% of objects coming through are mostly ID/Class
      // it works, we may have issues for function pointers/etc.
      for(var i=argTypes.length; i < arguments.length; i++) {
        if(arguments[i].type) newtypes.push(arguments[i].type)
        else if(arguments[i].pointer) newtypes.push('@');
        else if(typeof arguments[i] == 'function') newtypes.push('@?');
        else if(typeof arguments[i] == 'string') newtypes.push('r*');
        else if(typeof arguments[i] == 'number') newtypes.push('d');
        else newtypes.push('?');
      }
      return wrapValue(func
                        .apply(null, types.mapArray(newtypes))
                        .apply(null, unwrapValues(arguments,argTypes.concat(newtypes))),
                      rtnType);
    };
  } else {
    var func = ffi.ForeignFunction(funcPtr, types.map(rtnType), types.mapArray(argTypes));
    unwrapper = function() {
      return wrapValue(func.apply(null, unwrapValues(arguments, argTypes)), rtnType);
    }
  }
  unwrapper.retval = rtnType;
  unwrapper.args = argTypes;
  unwrapper.pointer = funcPtr;
  return unwrapper;
}
function createUnwrapperFunction (funcPtr, type, isVariadic) {
  var rtnType = type.retval || type[0] || 'v';
  var argTypes = type.args || type[1] || [];
  var unwrapper;

  if (isVariadic) {
    var func = ffi.VariadicForeignFunction(funcPtr, types.map(rtnType), types.mapArray(argTypes));
    unwrapper = function() {
      var newtypes = [];
      // Detect the types coming in, make sure to ignore previously defined baseTypes,
      // garner a list of these then send the function through the normal exec.
      // The types system in objc, should probably be cleaned up considerably. This is
      // somewhat faulty but since 95% of objects coming through are mostly ID/Class
      // it works, we may have issues for function pointers/etc.
      for(var i=argTypes.length; i < arguments.length; i++) {
        if(arguments[i].type) newtypes.push(arguments[i].type)
        else if(arguments[i].pointer) newtypes.push('@');
        else if(typeof arguments[i] == 'function') newtypes.push('@?');
        else if(typeof arguments[i] == 'string') newtypes.push('r*');
        else if(typeof arguments[i] == 'number') newtypes.push('d');
        else newtypes.push('?');
      }
      return wrapValue(func
                        .apply(null, types.mapArray(newtypes))
                        .apply(null, unwrapValues(arguments,argTypes.concat(newtypes))),
                      rtnType);
    };
  } else {
    var func = ffi.ForeignFunction(funcPtr, types.map(rtnType), types.mapArray(argTypes));
    unwrapper = function() {
      return wrapValue(func.apply(null, unwrapValues(arguments, argTypes)), rtnType);
    }
  }
  unwrapper.retval = rtnType;
  unwrapper.args = argTypes;
  unwrapper.pointer = funcPtr;
  return unwrapper;
}
function createUnwrapperFunction ( funcPtr , type , isVariadic ) { var rtnType = type . retval || type [ 0 ] || 'v' ; var argTypes = type . args || type [ 1 ] || [ ] ; var unwrapper ; if ( isVariadic ) { var func = ffi . VariadicForeignFunction ( funcPtr , types . map ( rtnType ) , types . mapArray ( argTypes ) ) ; unwrapper = function ( ) { var newtypes = [ ] ; // Detect the types coming in, make sure to ignore previously defined baseTypes, // garner a list of these then send the function through the normal exec. // The types system in objc, should probably be cleaned up considerably. This is // somewhat faulty but since 95% of objects coming through are mostly ID/Class // it works, we may have issues for function pointers/etc. for ( var i = argTypes . length ; i < arguments . length ; i ++ ) { if ( arguments [ i ] . type ) newtypes . push ( arguments [ i ] . type ) else if ( arguments [ i ] . pointer ) newtypes . push ( '@' ) ; else if ( typeof arguments [ i ] == 'function' ) newtypes . push ( '@?' ) ; else if ( typeof arguments [ i ] == 'string' ) newtypes . push ( 'r*' ) ; else if ( typeof arguments [ i ] == 'number' ) newtypes . push ( 'd' ) ; else newtypes . push ( '?' ) ; } return wrapValue ( func . apply ( null , types . mapArray ( newtypes ) ) . apply ( null , unwrapValues ( arguments , argTypes . concat ( newtypes ) ) ) , rtnType ) ; } ; } else { var func = ffi . ForeignFunction ( funcPtr , types . map ( rtnType ) , types . mapArray ( argTypes ) ) ; unwrapper = function ( ) { return wrapValue ( func . apply ( null , unwrapValues ( arguments , argTypes ) ) , rtnType ) ; } } unwrapper . retval = rtnType ; unwrapper . args = argTypes ; unwrapper . pointer = funcPtr ; return unwrapper ; }
Creates a JS Function from the passed in function pointer. When the returned
function is invoked, the passed in arguments are unwrapped before being
passed to the native function, and the return value is wrapped up before
being returned for real.

@param {Pointer} The function pointer to create an unwrapper function around
@param {Object|Array} A "type" object or Array containing the 'retval' and
'args' for the Function.
@api private
Creates a JS Function from the passed in function pointer . When the returned function is invoked the passed in arguments are unwrapped before being passed to the native function and the return value is wrapped up before being returned for real .