Re: A C to Euphoria Question: struct

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

Chris Cox wondered about structures in Euphoria:

>struct {
> int x, y;
> char Direction;
> char MovePixels;
> char CurrFrame;
> char NumFrames;
> char FrameRate;
> char FrameCount;
> unsigned char *data[20];
>} MainChar;

The equivalent in Euphoria might look something like:

-- define the indexes
constant
    X = 1,
    Y = 2,
    Direction = 3,
    MovePixels = 4,
    CurrFrame = 5,
    NumFrames = 6,
    FrameRate = 7,
    FrameCount = 8,
    Data = 9,
-- default structure
    MainChar = { 1, 1, 0, 0, 0, 0, 0, 0, "" }

You can then create objects of that type with:

    sequence newThing
    newThing = MainChar
    newThing[X] = 12
    newThing[Y] = 80
    newThing[Direction] = -2
    newThing[MovePixels] = 7
    newThing[CurrFrame] = 12
    newThing[NumFrames] = 32,
    newThing[FrameRate] = 24
    newThing[FrameCount = 8
    newThing[Data] = "text"

or more obscurely:

    newThing = { 12, 80, -2, 7, 12, 32, 24, 8, "text" }

If you need *real* C structs (like for passing a structure to a DLL) you can
find tools for that in my Win32Lib. But it doesn't sound like you are aiming
for anything like that.

Hope this helps!

-- David Cuny

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

Search



Quick Links

User menu

Not signed in.

Misc Menu