RE: Win4Eu update

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

Chris Bensler wrote:
> Tommy Carlier wrote:
> <SNIP> 
> Have you seen structs.e? The version in the RDS contribs is fairly old, 
> but still it works well. It's very much like what you have there.

Yes, I have. I've looked at different libraries that do what I want, and
I actually considered using existing libraries, but my idea of Win4Eu is
a solid uniform core, and components built on that core.
I think structs.e is one of the best structure-libraries i found, and it
has a really easy interface. As you can see, it actually inspired me.
But I wanted structures to be objects like the other objects. Actually,
the Structure-class is not a base-class, but inherits from the Allocator-
class: an Allocator allows you to allocate memory-blocks, and a Structure
is just an allocator that is structured (it has named fields).

> I've got an updated version, that I built for the empire set.
> It goes like this..
> 
> }}}
<eucode>
> constant RECT = define_struct({
>   {"left",  LONG}
>  ,{"top",   LONG}
>  ,{"right", LONG}
>  ,{"bottom",LONG}
> })
> 
> atom lprect
> lprect = alloc_struct(RECT)
> 
> pokes(lprect,{0,0,100,100})
> ? peeks(lprect) -- print all members
> ? peeks({lprect,"right"}) -- print the "right" member
> ? sizeOf(lprect) -- print the size of the struct
> ? sizeOf({lprect,"left"}) -- print the size of the left member
> dealloc_struct(lprect)
> </eucode>
{{{

> 
> There is also addressOf() and offsetOf(), etc..
> It also supports arrays, unions, externally allocated structs, and other 
> stuff.

Win4Eu structures behave like this:
constant myStructure = defineStructure("myStructure", {
   {"Name", String},
   {"Age", Int},
   {"Address", String}
})

integer x
x = create(myStructure, "x", {})

atom address
integer size, age
address = getStructureAddress(x)
size = getStructureSize(x)
pokeField(x, "Name", 0, "Chris")
age = peekField(x, "Age", 0)

destroy(x)


--
tommy online: http://users.telenet.be/tommycarlier
tommy.blog: http://tommycarlier.blogspot.com
Euphoria Message Board: http://uboard.proboards32.com
Empire for Euphoria: http://empire.iwireweb.com

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

Search



Quick Links

User menu

Not signed in.

Misc Menu