Re: Wrapping a C library.

new topic     » goto parent     » topic index » view thread      » older message » newer message
Davy said...

I'm getting a type check error when I use the gnuplot_plot_xy() function.

Looking at the include file, I see that the parameters x and y are atoms, however, writing the euphoria equivalent of the example given in the documentation:

...

I took it that x and y being arrays here, then in the corresponding Eu code x and y would be sequences.

I think this is something to do with the fact that x and y are not actually arrays, but pointers to arrays. Unfortunately my knowledge of C is nil so I'm just confused...

Yes, a C array is really just a pointer. To use it, you'll need to allocate some memory and poke and peek the data (there should be an easier way coming in 4.1). So, something like this:

include std/convert.e 
include std/machine.e 
 
sequence x = repeat( 0, 50 ) 
atom x_array = allocate( length( x ) * 8 ) -- doubles are 8 bytes each 
 
-- write your sequence into an array: 
for i = 1 to length( x ) do 
    poke( x_array + (i-1) * 8, atom_to_float64( x[i] ) ) 
end for 
 
-- read the array in memory into a sequence: 
for i = 1 to length( x ) do 
    x[i] = float64_to_atom( peek( { x_array + (i-1) * 8, 8 } ) 
end for 

Ideally, you'd probably put that sort of thing into functions/procedures, and use them as needed.

Matt

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu