Skip to content

Implement function type? #79

Description

@Kreijstal

Something like

var cftype = function(rtype,args){return {
  size: ref.sizeof.pointer,
  alignment: ref.alignof.pointer,
  rtype,
  args,
  indirection: 1,
  get: function get (buf, offset) {
    const _buf = ref.readPointer(buf, offset)
    if (ref.isNull(_buf)) {
      return null;
    }
    return ffi.ForeignFunction(_buf,rtype,args);
  },
  set: function set (buf, offset, val) {
    let _buf
    if (Buffer.isBuffer(val)) {
      _buf = val;
    } else {
      // assume fn
      _buf = ffi.Callback(rtype,args,val);
	  val._buf=_buf;//make lifetime valid as long as val is valid.
    }
    return ref.writePointer(buf, offset, _buf);
  }
}
}

However this solution polutes the function, I guess

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions