Re: get struct member as cdata

  • From: Mike Pall <mike-1205@xxxxxxxxxx>
  • To: luajit@xxxxxxxxxxxxx
  • Date: Thu, 17 May 2012 12:15:27 +0200

William Adams wrote:
> I think I'd just use a union, or change the declaration of the
> field in the struct, depending on whether you always want to see
> it as int vs unit.

Yes, and remember: you can lie to the FFI.

The data types you use on the Lua side don't have to correspond
1:1 with the ones you're using on the C side (due to exixting
APIs). As long as the layout is compatible, it still works.
Particularly handy for "void *" or uint32_t.

BTW: Another option would be to use bit.tobit(xyz.uint) to get a
signed integer. But can get the same effect easier by using a
different declaration.

--Mike

Other related posts: