Declaring extern C functions with void return type

Francisco <[email protected]>
Newsgroups gmane.lisp.scheme.bigloo
Message-ID <CAKp9ZTyc9_+ff1axT03Fj_j594J14LcjRMTV9AZGWcj-_DLOtg@mail.gmail.com>
Hi,

I'm working on a simple SDL2 test, creating bindings with the help of
Cigloo (and posterior manual adjustments). One use case I'm interested in
is generating audio procedurally, which involves providing a callback
function that will be invoked periodically by SDL2, where a buffer of a
given size is meant to be filled with the desired audio samples. Currently
I'm having trouble finding the right directives for the callback function
and a structure that is passed as a parameter to the function that is used
to register it.

The callback function is of the form:

*void audio_callback(void *userdata, Uint8 *stream, int len);*


The function used to register this callback is SDL_OpenAudioDevice, which
receives a SDL_AudioSpec* (among other parameters). This structure's
"callback" field is used set the callback up.

The definitions generated by Cigloo are:

*(type Uint8 uint8_t "Uint8")*
*(type Uint8* (pointer Uint8) "Uint8 *")*
*(type SDL_AudioCallback *void*,Uint8*,int->void "SDL_AudioCallback")*
*(type SDL_AudioSpec (struct ... (callback::SDL_AudioCallback "callback")
...) **"struct SDL_AudioSpec"**)*


On my program I tried the following definitions:

*(module audio*
*    (include "sdl.scm")*
*        (export (audio-callback::void ::*void* ::Uint8* ::int))*
*        (extern (export audio-callback "scheme_audio_callback")))*


The problem I have in that case is that I have not found a way of
"returning" void from the function (since all Scheme functions implicitly
return some value). Returning any value gives a compilation error of the
form "Type error: 'void' expected, 'x' provided". I tried using pragma with
a return type of void, but the following example gives this compilation
error: "Type error --  "obj" expected, "void" provided".

This is the function and the way I set the structure's callback field (req
is an instance of SDL_AudioSpec*).

*(define (audio-callback userdata stream len)*
*  (pragma::void "return;"))*


*(SDL_AudioSpec*-callback-set! req audio-callback) *


The other option I tried is using the type defined by Cigloo:


*(module audio*
*    (include "sdl.scm")**        (export
(audio-callback::SDL_AudioCallback))*
*        (extern (export audio-callback "scheme_audio_callback")))*


But this one fails with the following error (which is logical, after all):

*ERROR:audio-callback:Prototype and definition don't match (arity differs)*
*(audio-callback::SDL_AudioCallback) -- (define (audio-callback userdata
stream len)*


Is it possible to "return" void from a function? What is the proper way for
defining these types/functions?

Thank you!

Regards,
Francisco
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.