Jump to content
The simFlight Network Forums

Recommended Posts

Posted

All three of these routines have an "old" equivalent shown in each of their  descriptions in th Lua Library Reference.

The n = ipc.setbitsUB(offset, mask) routine is described as "Sets those bits in the Byte (UB), Word (UW) or DoubleWord (UD) offset which correspond to those present in the Mask value.


This is equivalent to the following where XX is UB, UW or UD:
n = ipc.readXX(offset)
n = logic.Or(n, mask)
ipc.writeXX(offset, n)

That is unclear with these routines include the read/write as shown above. Is the read/write included in the routine or should it be written similarly as above?

n = ipc.readXX(offset)
n = ipc.setbitsXX(offset, mask)
ipc.writeXX(offset, n)

Thank you

Posted
30 minutes ago, DrDave- said:

That is unclear with these routines include the read/write as shown above. Is the read/write included in the routine or should it be written similarly as above?

The words "equivalent to" is surely obvious? The setbits functions are simple and fast ways of setting bits in an offset without having to read that offset, "ORing the bits" (a simple logic operation), and writing it back. Not only does it do it in one call, it also prevents the offset value changing for some other reason after you read it and before it is written back (after all, the Lua thread may be only one of more threads also changing things -- like the values being continually received from SimConnect.

Your second sequence, reading the offset, setting bits in the offset, then writing what you read back would end up with no change to the offset.

Pete

 

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.