Page 2 of 2

Re: How can I use Lua 5.2 for LOVE

Posted: Thu Aug 18, 2016 10:39 pm
by Croutonix
Nevermind I found this lua 5.1 library which is the equivalent of bit32 library in lua 5.2.
http://www.snpedia.com/extensions/Scrib ... /bit32.lua

I could have done this with LuaJIT, maybe it would have been faster, but speed isn't key here, and it saves me work.

Re: How can I use Lua 5.2 for LOVE

Posted: Thu Aug 18, 2016 10:58 pm
by zorg
Croutonix wrote:I just need this?
local bit = require("bit")
Yes.

Also, curious how getting an external lib instead of writing one line saves you work. :3

Re: How can I use Lua 5.2 for LOVE

Posted: Thu Aug 18, 2016 11:25 pm
by Positive07
Wow, a pure Lua implementation of bit32... I wouldn't recommend that EVER, just use local bit32 = require("bit"), it's mostly compatible, maybe with a few minor differences but shouldn't matter that much, test it before going with the pure Lua alternative you suggested

Re: How can I use Lua 5.2 for LOVE

Posted: Thu Aug 18, 2016 11:55 pm
by Croutonix
It saves me work because bit and bit32 aren't the same.
This I don't need to write missing functions. (that I don't even understand)
But why is it so bad?

Re: How can I use Lua 5.2 for LOVE

Posted: Fri Aug 19, 2016 1:19 am
by Positive07
Bit operations are hard, you need to separate the number into bits (because you can't look at the inner representation) then compare and perform operations on those bits, then combine all those bits again into a number, when you are handling 2 32bits number your are working with around 192 operations, and probably some of them may not be JIT compiled, and you most likely aren't using a single operation, you probably do more than one, and you probably do all this in a loop which adds up.

LuaJIT library does all this in a single operation compiled by the JIT compiler so it is several orders of magnitudes faster. Also the incompatibilities between bit and bit32 libraries is minimal, and if you find problems you should be able to fix them easily.

Have you find any incompatibilities between the two of them? If so what is it? Maybe we can help you fix them

Re: How can I use Lua 5.2 for LOVE

Posted: Fri Aug 19, 2016 3:41 am
by zorg
Also, from a cursory glance, the luajit bit lib has all the functions that bit32 lib has, maybe except some checking ones, and some may have slightly different names.

Re: How can I use Lua 5.2 for LOVE

Posted: Fri Aug 19, 2016 11:55 am
by Croutonix
bit32.extract, bit32.btest and bit32.replace
I replaced the other functions with luajit bit