With 2016.08 release we get full support of Lua 5.3 bitwise operators and integer division operator:
| __bor -- bitwise or (binary)
& __band -- bitwise and (binary)
~ __bxor -- bitwise exclusive or (binary)
<< __shl -- bitwise left shift (binary)
>> __shr -- bitwise right shift (binary)
~ __bnot -- bitwise not (unary)
// __idiv -- integer division (binary) |
All operators and their according metamethods are same as Lua 5.3 ones.
Example 1:
This function encodes any integer number (32 bits) to 4 chars to pass it over network later:
local function encodeInt(n)
local t = {}
local char = string.char
t[1] = char(n >> 24 & 0xFF)
t[2] = char(n >> 16 & 0xFF)
t[3] = char(n >> 08 & 0xFF)
t[4] = char(n >> 00 & 0xFF)
return t:concat()
end |
Example 2:
You can use new metamethods same way as old ones:
mt = {
__bnot = function(t)
local r = {}
for i = 1, #t do r[i] = ~t[i] end
return r
end
}
t = {1, 2, 3, 4 ,5}
setmetatable(t, mt)
print(require"json".encode(~t)) --> [-2,-3,-4,-5,-6] |
Comments
Likes: pie
Do I need to do anything on my android player to enable "embedded bit"?
Just updated isometric tilemap to that.
I noticed it works as expected on desktop, but it shows a white screen on android, even with custom player with BitOp plugin.
Here you can find the complete project:
https://github.com/piretro/Isometric-Tilemap
thank you
https://deluxepixel.com
@SinisterSoft can you please try it on one of your devices to be sure I am not the only one having this issue? (the zip coming from github should be ready to run)
thank you
Because you are using bit 31 then on a 32 bit computer it's getting confused as between each operation it has to make it an integer and back again.
So on the device the result of the or'ed flags will actually be 0xffffffff, so that inverted = 0, so the and'ed value is cleared. On the emulator for some reason (64 bit internal?) it doesn't process after the &, so the result is that the value isn't and'ed with anything, so it stays the same. So on the device the block no is 0, on the emulator the block no is the original number.
If you used bits 30,29, and 28 then I don't think the problem will occur.
https://deluxepixel.com
I'm sorry @n1cke is this a bug or it is "expected"?
Thank you
(i mean on the C side of things)
https://deluxepixel.com
I don't know what's "better" because I don't know the backgrounds of bit.
From my user point of view, if SinisterSoft' suggestion will make it retrocompatible without losing the recently gained speed it would be really cool;
otherwise I could really use your help to "update" isometricTilemap to make it work, if it's possible (I am not even able to determine if it's possible doing it just editing lua code: bits on texture ids are applied by Tiled )
My other option is to stick to the old bit manipulation, which is what I am doing now.
Thanks
https://deluxepixel.com
However, won't this be overdoing things? I load the map only once, when I place its tiles on stage, so I would just double the operations needed to flip my tiles.
Thank you
to read bit 31 you AND with 0x80000000, if the result is not zero then you then set bit 28.
to set bit 28 you OR with 0x10000000
Likes: pie
https://deluxepixel.com
Compilation error on line 260:
C:\Projects\Gideros\pt101\agui\agui.lua:260: unexpected symbol near '>'
https://deluxepixel.com
Likes: antix
If this is the issue then maybe it is something that @paulclinger can lend a hand with
Likes: SinisterSoft
Fragmenter - animated loop machine and IKONOMIKON - the memory game
Likes: keszegh