accessing c functions
[1/5] from: rishioswal:yah:oo at: 11-May-2001 16:53
Hi. I am working on a program for a class and was
wondering if it would be possible, using view/pro, to:
1. send input to and execute a c function from rebol.
2. receive the output of the c function back to rebol.
The reason I want to do this is because their is a
recursive function in the code that needs to run
fast..
is this possible? If so, what is the general way i
would go about doing this?
thanks,
rishi
[2/5] from: sterling::rebol::com at: 11-May-2001 18:48
You certainly can. What you would do is compile a shared library with
your C functions and then use the library component of View/Pro to
access them. Check out the documentation on this component here:
http://www.rebol.com/docs/library.html
If you need more working examples, I'm sure the friendly folks on this
list will help you out.
Sterling
[3/5] from: rishioswal::yahoo at: 11-May-2001 19:57
hmmm... thanks for the reply. I browsed through the
doc but am a bit confused how to create a shared
library.
Has anyone done a simple program in rebol that calls a
c function that takes input and returns something such
as this:
int add(int a, int b) {return(a+b);}
A simple example of this would be useful (prefer
windows example but unix is ok also)...
any help would be appreciated...
rishi
--- [sterling--rebol--com] wrote:
[4/5] from: larry:ecotope at: 11-May-2001 20:17
Hi Rishi
The rebol part of accessing a shared library (dll in Windows) is illustrated
by a script on the Ecotope rebsite. The script shows how to access the
functions in the C-Runtime library crtdll.dll on Win98. Just change the
extension to .r.
http://www.nwlink.com/~ecotope1/reb/clib.txt
If you want to access some custom functions written in C, you will have to
get a C programmer to write the code and compile it to a dll which exports
those functions. They will be able to tell you the args and return specs for
wrapping it in a Rebol routine. You need a View/Pro license or Command to
access a shared library.
HTH
-Larry
[5/5] from: rishioswal:y:ahoo at: 12-May-2001 1:00
hmmm...seems like my last message didn't get through.
Anyway, thanks for the pointers. I guess i'll have to
learn how to compile c code into shared
libraries...Hopefully I won't have to read a whole
book to do it... If it is too complicated, I wonder if
it would be easier to write c functions and then use
the rebol shell (instead of libraries) to send input
and get output from the c functions (via the shell). I
guess i'd have to convert the c output to a string and
then in rebol, convert the string to valid rebol
datatypes.
on the flip side, I was also wondering, as crazy as it
may sound, if it would be possible to put rebol code
into a shared library so i can call it in my c code.
The reason i'd like to do this is simply because in
many of our programming assignments, we have to
implement c functions within a larger program. I'd
like to implement those functions in rebol by calling
a shared rebol library...i doubt this is
possible...but thought i'd ask anway..
rishi
--- [sterling--rebol--com] wrote: