Re: Wrapping Functions When Matrix is Involved
- Posted by Icy_Viking May 27, 2019
- 1561 views
ghaberek said...
You just need to allocate the space for the floats, poke them into that space, and then pass the pointer to the function.
Not sure why we don't have peek/poke float functions in the standard library. But this is how you'd do it:
procedure poke_float32( atom ptr, object value ) if atom( value ) then value = {value} end if for i = 1 to length( value ) do poke( ptr, atom_to_float32(value[i]) ) ptr += sizeof(C_FLOAT) end for end procedure public constant xNewtonCreateBox = define_c_func( nd,"NewtonCreateBox", {C_POINTER,C_FLOAT,C_FLOAT,C_FLOAT,C_INT,C_POINTER}, C_POINTER ) public function NewtonCreateBox( atom world, atom x, atom y, atom z, atom id, sequence matrix ) -- we assume matrix is of non-zero length atom p_matrix = allocate_data( sizeof(C_FLOAT) * length(matrix), TRUE ) -- cleanup = TRUE poke_float32( p_matrix, matrix ) return c_func( xNewtonCreateBox, {world,x,y,z,id,p_matrix} ) end function
-Greg
Thanks, this works, except for I don't think Euphoria has a sizeof function. I briefed through the manual, but didn't find anything. Unless allocate() can be subsistuted for sizeof?