-
Notifications
You must be signed in to change notification settings - Fork 6
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
function declarations #20
Comments
I am working on this now. |
I think this is a great idea, but since bytestructures itself doesn't have a concept of functions, I wonder how you intend to add this? If it's going to be Guile-only, then I suppose we could have a descriptor type that stores information about function signatures (e.g. in a format akin to what Guile's Or did you have another strategy in mind? BTW in the file E.g. if there's a C function that returns a Maybe this could make our "function pointers" feature a bit nicer. |
Right now the descriptor has two fields: one for the return descriptor and one for a list of param descriptors. This part is not guile-specific. Things are not working yet, but here is a test program
|
I would also like to deal with varargs. So I lied in the prev' post. The parameters are a list of param-spec's. A param spec is one of: descriptor, name-descriptor pair, |
Example using varargs:
|
And this works too:
|
Note: I have forked scheme-bytestructures, added bytestructures/guile/function.scm and guile-function-test.scm, and modified bytestructures/guile.scm. It is not all perfect, but would you like me to submit a pull request? |
Sorry for not answering, I somehow missed this. Feel free to make a pull request. |
I need to go back and review what I had again, and what's in nyacc. If it still looks worth it I will. |
I originally wrote this descriptor to use Guile ffi descriptors. I am now converting to use base bytestructure descriptors (in the hope of being fully Guile-independent). |
So, I have converted the function descriptor to use bs descriptors. I think the pointer descriptor may need to have a field for custom procedures to dereference. If I declare
then the pointer dereferencing needs to convert the bs-desc's to ffi-desc's and call |
Here is the function specification I currently use. The only use case is
|
Thanks a lot! I'll see that I incorporate this into the library when I find the time. Leaving the Issue open as a reminder to myself. |
FWIW, Chez FFI will cache the function pointer procedure. That is, it would be best not to call For instance, the following code is extracted from guile-sqlite by Andy Wingo, see the (define sqlite-errmsg
(let ((f (pointer->procedure
'*
(dynamic-func "sqlite3_errmsg" libsqlite3)
(list '*))))
(lambda (db)
(utf8-pointer->string (f (db-pointer db)))))) |
Some structures include declarations for function pointers. Please consider adding this.
The text was updated successfully, but these errors were encountered: