Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: External library interface

From: nitsch-lists:netcologne at: 2-Jul-2003 22:11

Am Mittwoch, 2. Juli 2003 15:12 schrieb Ladislav Mecir:
> Hi all, > > 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: > > rebol_string: "12^(0)4" > 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 > rebol_integer: integer_struct/i > > 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?
Write a wrapper-function in c. call the wrapper-function with a buffer. copy the result in the buffer.
> -L
-V