This is the mail archive of the guile@cygnus.com mailing list for the guile project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: calling scheme function from C


> That is the best way to take pointer of some scheme function and call it
> from "C"? For example, I have following scheme definition:
> 
> (define (func str)
>  )
> 
> How can I call it from C? The one way I've found is use gh_eval_str(), but
> I have to prepare external representation of parameters.

There is gh_apply() and the various gh_call0() variations.

All of these require that you get hold of an SCM object that contains
the procedure that you want to call (not the name, the actual procedure).
I can't get any of the gh_ calls to help me on this so I'm using a scm_
call until the module system gets its act together:

	...

	SCM proc, result, str;

	str = gh_str02scm( "blah" );
	proc = scm_symbol_value0( "func" );
	if( gh_procedure_p( proc ))
		result = gh_call1( proc, str );
	else
		result = SCM_BOOL_F;

	...

> I suspect there is way to take pointer to this function from C and simply
> call it.

That is what you are effectively doing but the pointer is tangled
up in the `proc' object along with closure stuff. The code above is the
most direct way the I know of while still (mostly) using the gh_ interface.

	- Tel