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

Shorthand FFI defbind with function renaming #1002

Open
jeannekamikaze opened this issue Jul 20, 2022 · 0 comments
Open

Shorthand FFI defbind with function renaming #1002

jeannekamikaze opened this issue Jul 20, 2022 · 0 comments

Comments

@jeannekamikaze
Copy link

This is an idea discussed with @andrewchambers in the chat.

TL;DR is to allow something like:

(ffi/defbind init :symbol "fooInit")

This would be a Janet init function that binds the C fooInit().

Longer story is to consider something like:

# foo.janet
(ffi/context "libfoo.so" :lazy true)
(ffi/defbind fooInit :void [])

Now foo/fooInit is not very idiomatic, so we can define an alias for that function:

# foo.janet
(ffi/context "libfoo.so" :lazy true)
(ffi/defbind fooInit :void [])
(def init fooInit)

Now a user can simply write:

(import foo)
(foo/init)

The explicit alias, however, adds quite a bit of boilerplate when you're binding 100+ functions. The shorthand would allow us to combine defbind and the alias in one line:

# foo.janet
(ffi/context "libfoo.so" :lazy true)
(ffi/defbind init :symbol "fooInit" :void [])
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