1. A C to Euphoria Question: struct
- Posted by Cox Family <cox.family at SK.SYMPATICO.CA> Nov 11, 1998
- 464 views
Dear Euphorians, I saw an interesting piece of code the other day in C, and was wondering how one would do the same thing in Euphoria. (I think Qbasic has something like it too with TYPE) Here's the code : struct { int x, y; char Direction; char MovePixels; char CurrFrame; char NumFrames; char FrameRate; char FrameCount; unsigned char *data[20]; } MainChar; I think that's about it. (just a small bit of C -- don't want to be a burden or anything) I haven't seen anything looking like : "MainChar.Direction = ...." in Euphoria before. If anyone could clear this up for me, it would be much appreciated. Thank you very much. Chris Cox cox.family at sk.sympatico.ca
2. Re: A C to Euphoria Question: struct
- Posted by Jeffrey Fielding <JJProg at CYBERBURY.NET> Nov 11, 1998
- 423 views
Unfortunately, Euphoria doesn't support types or structs. You can implement the same thing using sequences, though: constant MainChar_x =3D 1, MainChar_y =3D 2, MainChar_Direction =3D 3, MainChar_MovePixels =3D 4, MainChar_CurrFrame =3D 5, MainChar_NumFrames =3D 6, MainChar_FrameRate =3D 7, MainChar_FrameCount =3D 8, MainChar_data =3D 9 I am working on a pre-processor for Euphoria that will allow for pointers and structures, but it isn't finished yet. You can get the current version at http://members.tripod.com/~JJProg/epp.html. Also, in C, * means pointer so data is an array of 20 pointers to characters. Euphoria doesn't support pointers either, though you can get pointer.e from the Euphoria web site (http://members.aol.com/fileseu/) which allows you to create "pointers" in Euphoria. Sometimes, pointers in C are used for dynamic arrays (which C, unlike Euphoria, doesn't support). In this case, you could do the same thing using sequences. If you need to check the sequences to make sure they are in the right format, you could use something like this: type OneD(object s) if not sequence(s) then return 0 end if for i =3D 1 to length(s) do if sequence(s[i]) then return 0 end if end for return 1 end type type MainChar(object s) if not sequence(s) then return 0 end if if length(s) !=3D 9 then return 0 end if for i =3D 1 to 8 do if not integer(s[i]) then return 0 end if end for if length(s[9]) !=3D 20 then return 0 end if for i =3D 1 to 20 do if not OneD(s[i]) then -- Replace OneD with Pointer if you are using pointers return 0 end if end for return 1 end type MainChar c c =3D ""}} -- Or (if you are using pointers) c =3D {0,0,0,0,0,0,0,0,{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}} Jeffrey Fielding JJProg at cyberbury.net
3. Re: A C to Euphoria Question: struct
- Posted by David Cuny <dcuny at LANSET.COM> Nov 11, 1998
- 424 views
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