DrDave- Posted February 11, 2022 Report Posted February 11, 2022 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
Pete Dowson Posted February 11, 2022 Report Posted February 11, 2022 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
DrDave- Posted February 12, 2022 Author Report Posted February 12, 2022 Thank you. Sometimes what is obvious to the creator or someone who has studied extensively may not be apparent to one newly interested.
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now