lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

One thing everyone seems to be ignoring/forgetting/bypassing is the fact that bitfields are not equal. Most of the time, they are used as C API flags (this includes hw register layouts) and there, a 0x80 and some other 0x80 just aren't the same thing. This is why the grande question should include a way to keep families of bitfield values away from each other, to make it possible to ban using the families cross. Unless you _really_ want a family-less, just numerical 0x80, that is.

Think C enums. That is the way _not_ to go. :) They provide absolutely no type checking.


Doug Rogers kirjoitti 21.9.2006 kello 0.52:

Sam Roberts wrote:
I agree with Rici here about translating the flagset into a more usable
lua structure is a better way to go, which is why I could use bitwise
operators in lua.
Would you rather write C code to turn a uint32 into a table, with a
number of fields set to the values you pulled out of that uint32, and
then more C code to turn that table back into a packed uint32... or
would you rather write lua code to do that?

Yes, very nicely put.

Right now I would not even consider doing that in Lua. I would cycle
back and forth with the C interface code getting it right - loading and
reloading a shared library (or static, in the embedded case). Then on
the target I'm stuck with whatever the interface code produced.

If I could just return the value as a number then even if the Lua layer had some problems I could still manipulate the number from the interpreter.

But it's not a show-stopping problem, just an inconvenience.


Doug Rogers - ICI - V:703.893.2007x220