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

Add ffi/defbind-alias #1445

Merged
merged 1 commit into from
May 11, 2024
Merged

Add ffi/defbind-alias #1445

merged 1 commit into from
May 11, 2024

Conversation

wishdev
Copy link
Contributor

@wishdev wishdev commented May 10, 2024

I would like the ability to alias an FFI method in order to maintain the naming convention of the underlying shared library

As an example I would like to be able to do the following

(ffi/defbind-alias tb_poll_event _tb_poll_event :int [event :ptr])
(defn tb_poll_event
  []
  (def event (ffi/write tb_event (tb_event/new)))
  (_tb_poll_event event)
  (zipcoll tb_event_keys (ffi/read tb_event event)))

The shared library method is called tb_poll_event but it requires a janet "wrapper" because it returns a struct pointer.

@bakpakin
Copy link
Member

Makes sense, LGTM. I usually try to keep a one-to-one mapping for FFI but this would makes sense.

@bakpakin bakpakin merged commit 60e22d9 into janet-lang:master May 11, 2024
8 checks passed
@wishdev wishdev deleted the defbind-alias branch May 12, 2024 04:12
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

Successfully merging this pull request may close these issues.

2 participants