Cuberite Forum
Bitwise operators - Printable Version

+- Cuberite Forum (https://forum.cuberite.org)
+-- Forum: Plugins (https://forum.cuberite.org/forum-1.html)
+--- Forum: Plugin Discussion (https://forum.cuberite.org/forum-8.html)
+--- Thread: Bitwise operators (/thread-2497.html)

Pages: 1 2


Bitwise operators - PureTryOut - 08-19-2016

Is there anyway currently to use bitwise operators in plugins? I currently want to make a feature that either requires 12 new columns to a table and a lot of new queries, or using bitwise operators and only a few queries. I found this, and it seems that either Cuberite has to support it, or I have to use a pure Lua implementation, which I rather don't really.


RE: Bitwise operators - Seadragon91 - 08-19-2016

That could be a good candidate to upgrade lua 5.1 to 5.2.


RE: Bitwise operators - NiLSPACE - 08-19-2016

It's not build into Lua 5.1, but perhaps this wil help: http://nova-fusion.com/2011/03/21/simulate-bitwise-shift-operators-in-lua/


RE: Bitwise operators - xoft - 08-19-2016

There is no built-in support in Cuberite so far. However, it should be fairly straightforward to implement some simple bitwise logic directly in lua, using regular math operations. It will not be as performant as C/C++, but it might be more performant than actually exporting an API for that (anyone care to bench-test this hypothesis? Smile


RE: Bitwise operators - NiLSPACE - 08-19-2016

You mean actually editing the Lua lib to support <<, >> and | or just exporting a function to the API? I'm kinda opposed to changing the Lua library in case we're going to update Lua (or replace with LuaJit) some day.


RE: Bitwise operators - PureTryOut - 08-20-2016

Does Lua 5.2 support them? Are you guys planning on upgrading to 5.2 anytime soon then?


RE: Bitwise operators - xoft - 08-20-2016

http://lua-users.org/wiki/BitwiseOperators


RE: Bitwise operators - PureTryOut - 08-20-2016

Woops, totally missed the very first line of that page lol. So are you planning on upgrading sometime soon?


RE: Bitwise operators - tigerw - 08-20-2016

I tried once, but it crashed in LuaState and I gave up for want of knowledge. I'm sure it is possible, with much contribution from xoft.


RE: Bitwise operators - Zee1234 - 08-24-2016

(08-19-2016, 11:16 PM)xoft Wrote: There is no built-in support in Cuberite so far. However, it should be fairly straightforward to implement some simple bitwise logic directly in lua, using regular math operations. It will not be as performant as C/C++, but it might be more performant than actually exporting an API for that (anyone care to bench-test this hypothesis? Smile

I had to work with individual byte mechanics here to get plugin messages handled in a sane manner. Note: that is one of the first things I ever programmed, and I *know* it was extremely broken at some point (to the point of screwing up every single non-string value) and I somewhat doubt I ever got around to fixing it (the associated plugin only used the string method). So while the theory may be valid, the implementation is likely... flawed to say the least. I'd do a complete rewrite of that entire repository before I recommended it to anyone, but the math at least worked.