[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

deffcfun & MathLink


Below I have both the MCL code and the C code in which I am trying to complete a foreign function call (thru MPW-which the MCL doc' says this allows me to use the deffcfun in the format of a high-level function call). At present I am baffled, because I am not sure Ishould call both arguments of MLPutSymbol(MLLink, ml_charp) or just one. ;;below is the prototype as writen in the MathLInk header files writtenin ANSI C;;; .  Could someone lend me a hand with this--that is someone who isfamiliar with deffcfun.



P.S.  Please feel free to respond to me personally. 

;;;deffcfun (lisp-name entry-name {option}*) ({argspec}*) {result-flag}*;;;;;;;

(deffcfun ml-put-symbol "MLPutSymbol") (int ) :long)

;;;;;          extern int   MLAPI MLPutSymbol  P(( MLINK, ml_charp));;;;
;;;;;          the prototype of MLPutSymbol ;;;; 
;;;;;          typedef char      FAR * ml_charp  ;;;the typedef of ml_charp

(deffcfun (digit-value "digitval") (character) :long)

(deffcfun (setchar "setchar") ((string :by-reference) fixnum character) 

(deffcfun (flt-incr "flt_incr") 
      ((float :double :by-reference) 
       (float :extended)) 

/*  Examples of the Macintosh Common Lisp Foreign Function Interface,       */
/*  C component.                                                            */

#include <ctype.h>
#include <memory.h>
#include "mathlink.h"   ;mathlink headers
#include <stdio.h>

int main(argc,argv)                                                ;main arguments
int argc;
char *argv[];                
	MLINK  alink;                                           ;declare a link variable
	char *response;
	alink = MLOpen(argc,argv);                          ; open a link
	if(alink == NULL) return 1;   
	MLPutSymbol(alink, "$Version");                    ;put data on the link

MLEndPacket(alink);                              ; terminate link after the last
                                                          ; packet is thru
        while (MLNextPacket9alink) != RETURNPKT);     ;check incoming expressions
        if (MLGetType(alink) == MLKSTR) {               ;check the type of the 
 ;current data element
            MLGetString(alink, &response);         ;Get data from the link
            printf( "%s\n", response);  
         }  else{
               printf("Error--output is not a string. \n");
MLPutFunction(alink, "Exit, 0);
         MLClose(alink);                   ; Close the link
         return 0;

addtwo (i , j)  
int i;
int j;
    return  i+j;

  {   return MLMain(argc,argv);
plus_one (i)
  int i;
    return i+1;




******        *************

  ******** ****************************

 ******  ***************