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

foreign C code

I've been writing  some foreign C code using Allegro 4.0.1, and while
not extremely familiar with the manual, it seems that it would be
simple to make it a lot easier to pass information, especially
strings, back and forth between Lisp and C. All that would be needed
is for you to supply functions that convert between C and LISP
objects. Some obvious functions would be

lisp_value	*MakeLispInt (int)
lisp_value	*MakeLispFloat (float)
lisp_value	*MakeLispChar (char)
lisp_value	*MakeLispSymbol (char*)
lisp_value	*MakeLispString (char*)

plus  functions

lisp_value	*MakeLispList (...)
lisp_value	*MakeLispVector (...)
lisp_value	*MakeLispArray (int, int, ...)

which take a variable number of lisp_value* objects to make a lisp
list, vector or array. A C programmer could then simply pass
information back to lisp by using for example

return MakeLispString (c_result_str);

This would be much simpler than the methods described in the 4.0.1
manual and it seems to me it would be extremely simple for you to
offer these functions and implement them appropriately.

In the reverse direction, arguments to foreign C code could be
lisp_value* objects and be decoded by functions such as

int	IntFromLispValue (lisp_value*)
double	DoubleFromLispValue (lisp_value*)

boolean StringFromLispValue (lisp_value*, char)
/* returns the string in the prellocated char vector */
int	LengthOfLispString (lisp_value*)
/* returns length of string so space can be allocated in C */
int	TypeOfLispValue (lisp_value*)

If its safe to operate on an uncopied string, you might supply

char*	DirectStringFromLispValue (lisp_value*)


This would simplify foreign function coding a great deal. Any

|Bryan M. Kramer	      416-978-7330, fax 416-978-1455|
|Department of Computer Science, University of Toronto      |
|6 King's College Road, Room 283E			    |
|Toronto, Ontario, Canada      M5S 1A4                      |