Jump to content




Convert bitwise operators to bit api calls


7 replies to this topic

#1 Xenthera

  • Members
  • 170 posts

Posted 02 February 2019 - 11:01 PM

Hello Lua aficionados. Does anyone know of a way/program to convert lua 5.3 bitwise operators to a lua <= 5.2 corresponding bit api call?

Example:

self.pc = self.core.mem_read(self, ((self.pc + 1) & 65535)) | (self.core.mem_read(self, ((self.pc + 2) & 65535)) << 8)

- to -

self.pc = self.core.mem_read(self, bit32.bor(bit32.band((self.pc + 1), 65535)), (self.core.mem_read(self, bit32.rshift(bit32.band((self.pc + 2), 65535), 8))))

Not asking anyone to write a program to do this, just inquiring whether one exists.
I'd just do it manually but I have about 3000 lines of code i'm working with and need to make it compatible with computercraft.

Thanks for any help.

-X

#2 SquidDev

    Frickin' laser beams

  • Members
  • 1,403 posts
  • LocationDoes anyone put something serious here?

Posted 02 February 2019 - 11:43 PM

I had some luck with running the code through LuaFmt with a patch to the printer in order print bitops as calls to the corresponding functions. It's super ugly, but seemed to work OK. Be warned - I haven't used this in 6 months, so no clue whether it's still functional.

#3 Xenthera

  • Members
  • 170 posts

Posted 03 February 2019 - 12:11 AM

Thanks, i'll give it a try!

#4 Xenthera

  • Members
  • 170 posts

Posted 03 February 2019 - 07:50 AM

So i'm not terribly familiar with github patches, especially when applying them to node projects. Can you help me out applying it?

#5 SquidDev

    Frickin' laser beams

  • Members
  • 1,403 posts
  • LocationDoes anyone put something serious here?

Posted 03 February 2019 - 02:35 PM

 Xenthera, on 03 February 2019 - 07:50 AM, said:

So i'm not terribly familiar with github patches, especially when applying them to node projects. Can you help me out applying it?
If you cloned the repo using git, you should be able to do git apply printer.ts.patch (assuming you've saved it as that). Otherwise, it's probably going to be easier to apply it manually. Open the src/printer.ts file and look around for the printNodeNoParens function (should be line 104). You then just want to copy the two blocks of changes to roughly where they look like they belong in the original file.

#6 Xenthera

  • Members
  • 170 posts

Posted 03 February 2019 - 04:27 PM

View PostSquidDev, on 03 February 2019 - 02:35 PM, said:

View PostXenthera, on 03 February 2019 - 07:50 AM, said:

So i'm not terribly familiar with github patches, especially when applying them to node projects. Can you help me out applying it?
If you cloned the repo using git, you should be able to do git apply printer.ts.patch (assuming you've saved it as that). Otherwise, it's probably going to be easier to apply it manually. Open the src/printer.ts file and look around for the printNodeNoParens function (should be line 104). You then just want to copy the two blocks of changes to roughly where they look like they belong in the original file.

So I was able to get it to work, however is there a reason & isn't included? I'm about to add it and see what happens.. I was just curious as to its omission.

#7 SquidDev

    Frickin' laser beams

  • Members
  • 1,403 posts
  • LocationDoes anyone put something serious here?

Posted 03 February 2019 - 04:31 PM

 Xenthera, on 03 February 2019 - 04:27 PM, said:

So I was able to get it to work, however is there a reason & isn't included?
I forgot about it! I suspect the program I used this for didn't end up using it, otherwise I'd have noticed this at the time.

#8 Xenthera

  • Members
  • 170 posts

Posted 03 February 2019 - 07:26 PM

Thanks for your help it was exactly what I needed. Would've taken me days otherwise.
Currently working on a Z80 emulator written in lua...

Posted Image





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users