I've been so gung-ho about finally coming up with a good implementation of the Extension Type Mechanism that I've sort of changed my tune about whether it's worth it to keep around extensions like IMAGE!, VECTOR!, the FFI, or even GOB! and the serial port extension...
But in any case, LIBRARY! is now the best it's been:
>> winsock: make library! %/C/Windows/System32/wsock32.dll
== #[library! %/C/Windows/System32/wsock32.dll]
>> pick winsock "gethostbyname"
== #[handle!]
>> pick winsock "gethostbynickname"
** Error: Couldn't find "gethostbynickname"
in #[library! %/C/Windows/System32/wsock32.dll]
>> try pick winsock "gethostbynickname"
== ~null~ ; anti
>> close winsock
== #[library! {closed} %/C/Windows/System32/wsock32.dll]
FFI Has A Dependency on LIBRARY!... But...
So the FFI extension is designed to let you interface with C functions from Rebol code.
You've got a C function in some DLL, the FFI lets you wrap that up in something you can call as a Rebol function and it translates the Rebol parameters (e.g. TEXT!) into something the C can take (e.g. char*
).
The way Shixin did it, you pass the FFI a LIBRARY! and a TEXT! of a function name:
libgtk: make library! %libgtk-3.so
gtk-init: make-routine libgtk "gtk_init" [
argc [pointer]
argv [pointer]
]
But what if MAKE-ROUTINE just took a CFunction HANDLE! ?
libgtk: make library! %libgtk-3.so
gtk-init: make-routine (pick libgtk "gtk_init") [
argc [pointer]
argv [pointer]
]
We could make this even better, by letting LIBRARY! accept WORD! as well as TEXT!, and using a TUPLE!-based PICK:
libgtk: make library! %libgtk-3.so
gtk-init: make-routine libgtk.gtk_init [
argc [pointer]
argv [pointer]
]
This makes the FFI generalize, to however you get your CFunction.
Maybe you compiled a function in-memory with the TCC extension and want to test it from Rebol?
Maybe you are using a different extension than LIBRARY! for getting DLLs.
Anyway, I was working on trying to resolve dependencies between modules when I realized that this particular dependency isn't necessary!