metaeducation / rebol-issues

6 stars 1 forks source link

How to provide series datatype as an argument to extension command? #1836

Open rebolbot opened 13 years ago

rebolbot commented 13 years ago

Submitted by: oldes

I need to provide binary source into C function, I found two ways:

In both cases I must manually correct the index for case that the source has index > 0.

Which version is better? RXI_SER_SIZE returns number of bytes allocated on REBOL's side, can we have a macro to get LENGTH value?

1)
    REBSER *ser
    char *srcData;
    u32 srcLen;

    ser      = RXA_SERIES(frm, 1);
    srcLen   = - RL_GET_STRING(ser, 0, (void **)&srcData); //the second arg must be 0 or it sets invalud srcData pointer!
    srcData += RXA_INDEX(frm, 1); //fix the pointer to the right index

2)
    srcData = RL_SERIES(ser, RXI_SER_DATA) + RXA_INDEX(frm,1);
    srcLen =  RL_SERIES(ser, RXI_SER_SIZE) - RL_SERIES(ser, RXI_SER_LEFT) - RXA_INDEX(frm,1) -1;

CC - Data [ Version: alpha 111 Type: Note Platform: All Category: Extensions Reproduce: Always Fixed-in:none ]

rebolbot commented 13 years ago

Submitted by: Kaj

You can use TAIL - INDEX to get the lengtb.