[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: boolean operators
- From: Sam Roberts <sroberts@...>
- Date: Wed, 20 Sep 2006 14:34:28 -0700
On Wed, Sep 20, 2006 at 04:06:55PM -0500, Rici Lake wrote:
> >Sure. Sorry about the confusion. (I should call them bitwise
> >operators.)
Oops.
Ok, those I have a use for. As others have said, if you are using lua to
interface to C, they come up a lot. I doubt I would use them in pure
lua, though bit strings do come up as efficient representations for some
algorithms.
> For the case of flags coming out of C functions, I personally think
> that it is better to translate the flagset in and out into a more
> usable Lua structure than to try to use bitwise operators in Lua.
> That's just a personal preference, but it leads to more readable Lua
> programs, even though they may not execute quite as fast.
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?
It depends a bit on the situation, but I often prefer to keep the
wrappers around my C code as "thin" as possible, and then build better
apis in pure lua. This is one reason I want to use lua. To have an
interactive dynamic environment to use to experimenting with and use C
libraries.
Also, there are times when I don't have time to build a "nicer" lua api,
I am trying to bind C code into lua fast (to implement, not fast to
run). These cases are more like one-off prototypes or perhaps unit
tests. I don't want to implement a nice lua-style api, I just want my C
functions exposed to lua, and to push bitmasked arguments in and out of
the functions right away.
Cheers,
Sam