I'm a bit careful and general in my reply because I don't know the library you 
use. First, in Nim an array has a known and fixed size. If you need a dynamic 
array have a lot of seq.

Basically you should differentiate between two cases:

  * 1) The C func has a size parameter directly following the array/pointer 
(typically of type size_t)
  * 2) The C func does not have a size parameter directly following



Examples for both would be
    
    
    // type 1, with size
    int foo1(char *bar, int bsize); // 'bsize' is the number of chars in 'bar'
    
    // type 2, no size
    int foo2(char *bar);
    
    Run

The proper declaration and calling of those funcs in/from Nim:
    
    
    proc foo1(arr: openarray[char]): cint   {.importc.}
    proc foo2(arr: ptr char): cint   {.importc.}
    #...
    var myArr: array[42, char]
    let res1 = foo1(myArr)
    let res2 = foo2(addr(myArr[0]))
    
    Run

Note that Nim automagically passes both, a ptr to the array data and the size 
of the array to a C func declared to have an `openarray` parameter.

In your case - and assuming `imgdata` has a fixed size, e.g. 10 - something 
like this
    
    
    type
       Image = object
          # fields
       Ihandle = ptr Image
    
    proc iupImageRGBA(p1, p2: cint; imgArr: ptr byte): Ihandle   {.importc.}
    
    var imgdata = [0'byte, 0, 0, 0, 0, 0, 0, 0, 0, 0] # fixed size! array
    var image: Ihandle = iupImageRGBA(32, 32, addr(imgdata[0]))
    
    Run

should do what you want.

Warning: my example is based on certain assumptions (e.g. the first 2 
parameters being of type cint). I strongly suggest to make the effort of 
providing all needed info when asking questions to avoid misunderstandings.

Reply via email to