[REBOL] External library interface
From: lmecir:mbox:vol:cz at: 2-Jul-2003 15:12
I tried to help Cyphre with a specific problem (OpenGL 3D). I found a following problem
in the interface between Rebol strings and external strings.
First I try to make a C string usable for an external function:
c_string: third make struct! [s [string!]] reduce [rebol_string]
So far so good, I created a binary! data (in fact a pointer), that can be passed to a
library function as a C string.
Now let's suppose, that a library function returns a C string. How can this be done?
One possibility is to store such a pointer into a Rebol integer. Not having Rebol/Command,
I cannot call a library function now, but I can "simulate" this situation using the C
string I prepared above. To do it, I just convert the above C string to a Rebol integer.
integer_struct: make struct! [i [integer!]] none
change third integer_struct c_string
Now I obtained the C string as an integer and I can pretend, that it is a result of an
external library function. What to do with it to obtain a Rebol string? Let's try to
use a similar "trick" as above:
result_integer_struct: make struct! [i [integer!]] reduce [rebol_integer]
result_string_struct: make struct! [s [string!]] none
change third result_string_struct third result_integer_struct
result_string: result_string_struct/s ; == "12"
Now the problem: as we have seen, the RESULT_STRING_STRUCT doesn't know the length of
the string (as usual for C strings) and therefore it assumes, that the string is a null-terminated
string as usual in C, so it "leaves off" a part of the string. While this is reasonable
for strings, I doubt, it is reasonable for binary data, like images.
Do you have any idea how to handle binary data or strings containing null characters?