Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi,

I need a little help with LUA (once again).

I do perfectly understand how to read and write bytes, words, etc in LUA, but I need to change single bits now.

Tried to find any info on that in the forum, but didn't find anything.

So, how can I read and write values of bits in LUA?

please help

Potroh

Posted

So, how can I read and write values of bits in LUA?

At present you have to read the byte or word or whatever, then use the Logic library facilities or And, Or, Xor to clear, set or toggle the bit(s), and write the changed value back. So, for example:

x = ipc.readUB(0x1234) -- read byte to change

x = logic.And(x, 254) -- clear bit 0 (worth 1, 255-1 = 254)

ipc.writeUB(0x1234, x)

or, the same more efficiently (and safer, avoiding possible other changes to the same offset by others between the read and write):

ipc.writeUB(0x1234, logic.And( ipc.readUB(0x1234), 254))

These sorts of operations can become quite frequent, though, and I am considering adding "SetBits", "ClearBits" and "ToggleBits" functions to the ipc library. Maybe soon ...

Regards

Pete

Posted

These sorts of operations can become quite frequent, though, and I am considering adding "SetBits", "ClearBits" and "ToggleBits" functions to the ipc library. Maybe soon ...

Hi Pete,

Many thanks for the info (the lesson rather). Starts to be clearer now, but 'Setbits, etc. function would truly solve a lot of problems for me - and hopefully others too.

Please think of it when got the time...

best regards

Potroh

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.