[REBOL] Re: External library interface
From: rotenca:telvia:it at: 3-Jul-2003 2:46
Ciao Ladislav,
>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.
1) I don't have Pro or command.
2) I do not know how much is safe (look at the GC section of command doc)
3) Hope it helps :-)
First we create a 36 byte data block:
x: [] loop 10 [insert tail x [. [long]]]
data: make struct! x none
data is an area of 9 long (36 bytes)
>> third data
== #{
0000000000000000000000000000000000000000
0000000000000000000000000000000000000000
}
Now we create a struct which contains a pointer to a 36 bytes area:
z: make struct! compose/deep [data [struct! [(x)]]] none
>> third z
== #{6863E500}
Now, to emulate the return value of a routine, we create a second struct which
contains a pointer to a different 36 byte area:
res: make struct! compose/deep [data [struct! [(x)]]] none
>> third res
== #{E864E500}
Now we change the first long of res for test purpose:
res/data/.: 1; == 1
Now we make z to point to res 36 byte data area:
change third z third res;== #{}
Check the result:
>> z/data/.
== 1
In a real program, the routine should return a long (res). It must be
converted to binary and poked to the third of our struct (z).
To end make it an image!:
img: make image! reduce [3x3 third z/data]
check it:
>>img
make image! [3x3 #{
010000000000000000000000000
000000000000000000000000000}]
------ The program ---------
x: [] loop 10 [insert tail x [. [long]]]
data: make struct! x none
z: make struct! compose/deep [data [struct! [(x)]]] none
res: make struct! compose/deep [data [struct! [(x)]]] none
res/data/.: 1; == 1
change third z third res
img: make image! reduce [3x3 third z/data]
---
Ciao
Romano