Re: Structures
Everett Williams wrote:
> Cheapshot!
Yes. I couldn't resist, but I should have.
Let me see if I understand what you are asking for. The Real World
implements things using C structures. Calls to external DLLs, reading binary
data - all of these deal with data in a C structure, which then has to be
laboriously mapped to and from Euphoria data.
If I understand you, you are suggesting that it would be nice if you could
link Euphoria variables to C structures. For example, given a structure like
this:
struct point
integer x as C_INT
integer y as C_INT
end struct
You could then declare an instance of the structure:
point myPoint
and assign data to the structure:
myPoint.x = 12
myPoint.y = -3
fetch data from the structure:
? myPoint.x
pass the data structure or elements to DLLs:
result = c_func( DLL_FUNC, { *myPoint } )
result = c_func( DLL_FUNC( { *myPoint.x } }
and peek/poke/perform memory moves:
poke( hMemoryAddress, *myPoint, sizeof( myPoint ) )
Note that I've had to prefix the structure and structure element with a '*',
so Euphoria knows I want the address, and not the value of the structure or
structure element.
Am I (more or less) correct here?
To some extent, Win32Lib already has tools to do this sort of thing. For
example, I can declare a structure:
constant POINT
POINT_X = allot( Integer ),
POINT_Y = allot( Integer )
SIZEOF_POINT = allotted_size()
I can create the structure in memory:
atom hPoint
hPoint = allocate_struct( SIZEOF_POINT )
assign values:
store( hPoint, POINT_X, 12 )
store( hPoint, POINT_Y, -3 )
fetch the values:
? fetch( hPoint, POINT_X )
pass them to functions:
result = c_func( C_FUNC, { hPoint } )
It deals transparently with a number of data types, include lpzString. It's
a fairly close mapping to C structures, and works fairly well. It's missing:
embedded structure support
arrays of structures
But these aren't too hard to simulate, and if I really need them, I can
always add them in. It's not as *nice* as working with native Euphoria, but
it's worked well for me.
-- David Cuny
|
Not Categorized, Please Help
|
|