> I'm setting up a stack that will run at the same time as a C program.
> I would like to be able to call stack functions from the C program or
> at a unix prompt and to be able to call functions in the C program
> from the stack. I'd be interested in any ways you know of doing
> this.
Making your program into an external would probably be the easiest way
to do this. The external.tar.Z and the external tutorial describe how
to call external C functions, and provide an example of how to call
back to MetaCard from the external.
You could also use open process to do this, but you'd have to develop
a protocol such that if MetaCard could call a function foo by doing
something like: write "foo" & return to process "your C program"
Your C program would have to read from its stdin and decide which
function to call based on the string it reads. The MetaCard engine
would have to do the same when it reads a string from the process.
The advantage of the process approach is that calls would be faster
than equivalent external calls, and that your C program doesn't have
to use the X way of handling events (which may make it easier for you
to write functions that have long execution times since you don't have
to return to MetaCard right away as is required for externals). The
downsides are that it would be harder to implement and that passing
arguments is more difficult since you have to parse them up yourself.
Finally, if your functions aren't called very often, you could use
signals to get the messages across. Your program would write a file
that has the name of the function to call in it, and then send a
SIGUSR1 signal to the MetaCard process (there'd have to be some way
for MetaCard and the other process to get each others process ids).
In MetaCard, you'd write an "on signal" handler to catch the signal,
and open and read the file to determine the function to call. The
advantage to this approach is that it doesn't require redirecting the
process's stdin or stdout and that it only takes a few lines of C
code. The down side is that it's much slower than the other two
methods, you still have the argument passing problems, and that
sending signals to X applications is still a relatively risky
operation on some platforms (MetaCard should handle all the
OS-call-restarting stuff, but we've run into a few Xlib and OS bugs
doing this kind of thing ;-)
Scott
> Thank you,
>
> David Humphreys
> MPR Teltech Ltd.
> Burnaby, BC
>
>
-- *********************************************************************** * Scott Raney 303-447-3936 Remember: the better you look, * * raney@metacard.com the more you'll see -- Lidia * ***********************************************************************