On Sun, 04 Jan 2004 10:43:19 +0000, Joona I Palaste wrote:
Malcolm <ma*****@55bank.freeserve.co.uk> scribbled the following:
Given that I've got a BASIC interpreter, what is the
most useful interface to the rest of the C program that calls it?
Your BASIC interpreter is written in ANSI C, but is your program around
it also written in ANSI C? If not, then you can use a non-standard "pipe
stream" and pass it as an argument to your interpreting function. That
way you can send data between your outer program and your interpreter
efficiently.
How about callback functions? Something like:
typedef int (*input_handler)(char**);
typedef int (*output_handler)(const char*);
typedef int (*error_handler)(int,int,char*); /* errno, line, text */
int basic(const char *script,
input_handler ih,
output_handler oh,
error_handler eh);
Giving the calling program the opportunity to define functions to deal
with input, output or errors. These programs may then write to file or
process the error or do whatever they feel like.
(And you can provide handler functions that writes to files if that's
what the user wants them to do.)
--
NPV
"the large print giveth, and the small print taketh away"
Tom Waits - Step right up