Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement function type? #79

Open
Kreijstal opened this issue Nov 5, 2022 · 0 comments
Open

Implement function type? #79

Kreijstal opened this issue Nov 5, 2022 · 0 comments

Comments

@Kreijstal
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant