RE: structure pointers and metatypes using ffi

  • From: William Adams <william_a_adams@xxxxxxx>
  • To: <luajit@xxxxxxxxxxxxx>
  • Date: Mon, 14 May 2012 14:05:20 +0000

> Oops, I guess I forgot to answer the obvious question:
> 
> p1[0] == p2[0]
> 
> overrides pointer comparison and calls __eq on the structs.


I think that's "magic pixie dust" enough.

I'm not an advocate of doing too many magical hidden overrides. I'm willing to 
make this one syntactic sacrifice to get the symantics I'm seeking.

After translating several thousand lines of straight 'C' code, the things that 
come up the most with pointers are:

ptr++
--ptr
ptr += value
*ptr++ = *rhs++

And to a lesser extent variants thereof. Since C would not do the value 
comparisons using the '==' operator, it's not something I find in C code at 
all. This is an added benefit of programming in Lua.


Also, I hope I've fixed my mail client problems. I don't have any mail clients 
that can not deal with HTML, so I didn't even realize I was sending out crappy 
emails.

-- William
===============================



- Shaping clay is easier than digging it out of the ground.




 


> Date: Mon, 14 May 2012 14:26:59 +0200
> From: mike-1205@xxxxxxxxxx
> To: luajit@xxxxxxxxxxxxx
> Subject: Re: structure pointers and metatypes using ffi
> 
> William Adams wrote:
> > p1 == p2
> >
> > At the moment, it will return false, because it essentially does
> > pointer comparison. Is there any magic pixie dust to sprinkle
> > to get it to do value comparison, and still use the '=='
> > operator?
> 
> Oops, I guess I forgot to answer the obvious question:
> 
> p1[0] == p2[0]
> 
> overrides pointer comparison and calls __eq on the structs.
> 
> [But then William's mails are very hard to read and reply to in
> text mode. Mail clients sending HTML by default are annoying.]
> 
> --Mike
>                                         

Other related posts: