Stabyourself / nestrischamps-emulator-connector

Lua script for FCEUX, Mesen, and BIzhawk that uploads stuff to NestrisChamps
MIT License
8 stars 3 forks source link

Use bitwise operators in toBits() #1

Closed timotheeg closed 3 years ago

timotheeg commented 3 years ago

I don't know what I'm doing in lua 😅 , but util.lua looked like it could use some TLC, so here's a small change to just the toBits() method for a start. If it works, I might try to do more in makeFrame() too.

PR assumes that lua uses a consistent bit representation for integers like javascript (seems to work on OSX Lua CLI 5.4.3, but I have not tested in any of the emulators cough)

I also didn't do a speed comparison test (I just assume using bitwise operators are faster 😑).

Ref: https://www.lua.org/manual/5.3/manual.html#3.4.2

Stabyourself commented 3 years ago

You're right, toBits, makeFrame and also playfield.getBinaryString are the parts of the code that I need to change. It was mostly a case of "it's fast enough so I'll leave it for now". I don't have any experience working with bits in Lua.

All 3 emulators use Lua 5.1, which I don't think supports these bit operators: image

timotheeg commented 3 years ago

Oh damn that's sad 😓 And yeah, it looks like these were introduced in Lua 5.3, I should have checked earlier.

Ignore till Lua gets an upgrade then. I'll just close the PR.