From: =?GB2312?Q?=B3=CC=B2=AE=C8=BA?=

Subject: How to pass a (char *) type parameter from c for calling lisp function.

Date: 2003-11-26 3:45

Hi,all

	I am a new acl user from china. I am using acl6.0 under windows XP.

	I want to call lisp function using c code .now i met a questin for a long time.  My trouble is :

	I write a ff:defun-foreign-callable  function for c calling .I read the acl document ,found that the ff:defun_foreign_callable function can  only using several data type ,such as :

	:signed-byte 8 bits
	:unsigned-byte 8 bits
	:signed-word 16 bits
	:unsigned-word 16 bits
	:fixnum 30 bits
	:signed-long 32 bits
	:unsigned-long 32 bits
	:signed-natural (the default)
	:unsigned-natural
	:single-float, single-float 32 bits
	:double-float, double-float 64 bits
	:lisp (Assumes that C passes an actual Lisp value)

	when i pass a integer parameter to ff:defun-foreign-callable funcation, i define its type as :unsigned_long, it works well, but when i pass a (char *) type parameter for call the ff:defun_foreign_callable function ,and i tried all lisp data type each other ,it all don't work.  How about it?

	Which data type should i used ? and how should I use it?

	Following is my ff:defun_foreign_callable function code: 

//*************************
(ff:defun-foreign-callable factorial-callback((arg :unsigned-long) (str :unsigned-long) (len :unsigned-long))
	(declare (:convention :c))
  	:long  
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;my c code will call this function ,it is such as 
	;;;Dllexport int factorial ( char *x, char *result, int string_size )
	;;;{
  	;;;		if (!lisp_initialized || !lisp_factorial) {
    ;;;			return -1;
  	;;;		}
  	;;;		switch ( (*lisp_factorial) ( x, result, string_size ))
  	;;;		{
    ;;;			case 1:
    ;;;  				return 1;
    ;;;			case 0:
    ;;;			default:
    ;;;  				*result = '\0';
    ;;;  				return 0;
  	;;;		}
	;;;}
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;/* Lisp calls this to set factorial callback address */
	;;;Dllexport void set_factorial_callback( int (*fcb) (char *, char *, int) )
	;;;{
 	;;; 	lisp_factorial = fcb;
	;;;}
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	;;;/* Lisp calls this to fill result string */
	;;;int Dllexport
	;;;copy_factorial_result( char *str1, char *str2, int n )
	;;;{
  	;;;		strncpy( str1, str2, n - 1 );
  	;;;		*(str2 + n) = '\0';
	;;;		return 0;
	;;;}
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  	(handler-case
      (progn
		(copy_factorial_result  str
								;;;the arg come from c code ,its primary type is (char *)
			     			    (format nil "~s" (factorial arg)) ;;;call the lisp function factorial(arg) here
			     			    len) 
		1) ;; return 1 if successful
     (serious-condition () 0)) ;; return 0 if unsuccessful
)
//*************code ended********
	

 	Anyone can help me?

with best regards,

Boqun Cheng


<software.ict.ac.cn at         cbq>
          2003-11-26