Hello,
I'm working on a project to make an iTunes plugin. I want to use Scheme as an embedded extension language for it.
I've managed to get this working using Tiny Scheme, but now would like to try to get a better (i.e. faster) Scheme implementation in there. Hopefully, I can get compiled Scheme in there, instead of interpreted.
Is it possible to do this with Gambit? The crux of the problem is that the scheme code cannot declare main(). Instead, it needs to provide an init function and a deinit function. My plugin would call the init function when it loads, and the deinit function when it unloads. There is no stdin or stdout. When the plugin is operating, iTunes will repeatedly call a single function, lets call it the work function.
(Actually, there is a stdout.. because if I call printf, the output ends up in the system log file. But I can't reassign it, and there's no stdin).
So, the init function will need to set up the scheme environment. Then, when the work function is called, it will need to reference the scheme environment, and call a scheme function in that environment to do the work.
I need to provide this functionality as a library that is dynamically loaded by iTunes. As I mentioned above, iTunes already declares main().
If someone could point me at some sample code that embeds Gambit in this manner, or otherwise point me in the right direction, it would be a great help.
Thanks,
Neil Baylis.
Afficher les réponses par date
Hallo,
Neil Baylis wrote:
Is it possible to do this with Gambit? The crux of the problem is that the scheme code cannot declare main(). Instead, it needs to provide an init function and a deinit function. My plugin would call the init function when it loads, and the deinit function when it unloads. There is no stdin or stdout. When the plugin is operating, iTunes will repeatedly call a single function, lets call it the work function.
Although it is only mentioned in passing in the manual, Gambit is very suited to embedding. Take a look at the pthreads example in the source distribution. Basically:
1. Your init function will call ___setup(), you can set several initialisation parameters in the parameters struct, such as character encoding, debugging, behaviour on errors etc.,
2. Your deinit function will call ___cleanup(),
3. You must compile the C files generated by Gambit with the ___LIBRARY preprocessor directive.
Hope this helps, -alex http://www.ventonegro.org/
On 22-Oct-08, at 6:16 PM, Neil Baylis wrote:
Hello,
I'm working on a project to make an iTunes plugin. I want to use Scheme as an embedded extension language for it.
I've managed to get this working using Tiny Scheme, but now would like to try to get a better (i.e. faster) Scheme implementation in there. Hopefully, I can get compiled Scheme in there, instead of interpreted.
Is it possible to do this with Gambit? The crux of the problem is that the scheme code cannot declare main(). Instead, it needs to provide an init function and a deinit function. My plugin would call the init function when it loads, and the deinit function when it unloads. There is no stdin or stdout. When the plugin is operating, iTunes will repeatedly call a single function, lets call it the work function.
(Actually, there is a stdout.. because if I call printf, the output ends up in the system log file. But I can't reassign it, and there's no stdin).
So, the init function will need to set up the scheme environment. Then, when the work function is called, it will need to reference the scheme environment, and call a scheme function in that environment to do the work.
I need to provide this functionality as a library that is dynamically loaded by iTunes. As I mentioned above, iTunes already declares main().
If someone could point me at some sample code that embeds Gambit in this manner, or otherwise point me in the right direction, it would be a great help.
Thanks,
Neil Baylis.
Sounds like a cool project!
As Alex Sandro Queiroz e Silva has pointed out, check the pthreads example or tests/client.c . Basically Gambit's init function is called ___setup and the deinit function is ___cleanup. What I don't quite understand is the "work" function. Is this something that is called periodically by iTunes to give the plugin the opportunity to make progress? Do you want to use this to have Gambit run concurrently with iTunes in a time multiplexed fashion?
Marc