Skip to content

Commit

Permalink
Fix change all uses "bit32" for "bit"
Browse files Browse the repository at this point in the history
This modification is necessary due to the LIB update.

Fix compilation warnings and LUA errors in the otclient console.
  • Loading branch information
CodingALS committed Feb 23, 2025
1 parent a6369a1 commit a6a4669
Show file tree
Hide file tree
Showing 11 changed files with 20 additions and 21 deletions.
4 changes: 2 additions & 2 deletions modules/corelib/base64.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
base64 -- v1.5.1 public domain Lua base64 encoder/decoder
no warranty implied; use at your own risk
Needs bit32.extract function. If not present it's implemented using BitOp
Needs bit.extract function. If not present it's implemented using BitOp
or Lua 5.3 native bit operators. For Lua 5.1 fallbacks to pure Lua
implementation inspired by Rici Lake's post:
http://ricilake.blogspot.co.uk/2007/10/iterating-bits-in-lua.html
Expand All @@ -24,7 +24,7 @@

base64 = {}

local extract = _G.bit32 and _G.bit32.extract
local extract = _G.bit and _G.bit.extract
if not extract then
if _G.bit then
local shl, shr, band = _G.bit.lshift, _G.bit.rshift, _G.bit.band
Expand Down
6 changes: 3 additions & 3 deletions modules/corelib/keyboard.lua
Original file line number Diff line number Diff line change
Expand Up @@ -239,13 +239,13 @@ function g_keyboard.isInUse()
end

function g_keyboard.isCtrlPressed()
return bit32.band(g_window.getKeyboardModifiers(), KeyboardCtrlModifier) ~= 0
return bit.band(g_window.getKeyboardModifiers(), KeyboardCtrlModifier) ~= 0
end

function g_keyboard.isAltPressed()
return bit32.band(g_window.getKeyboardModifiers(), KeyboardAltModifier) ~= 0
return bit.band(g_window.getKeyboardModifiers(), KeyboardAltModifier) ~= 0
end

function g_keyboard.isShiftPressed()
return bit32.band(g_window.getKeyboardModifiers(), KeyboardShiftModifier) ~= 0
return bit.band(g_window.getKeyboardModifiers(), KeyboardShiftModifier) ~= 0
end
1 change: 0 additions & 1 deletion modules/game_bot/executor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ function executeBot(config, storage, tabs, msgCallback, saveConfigCallback, relo

-- basic functions & classes
context.print = print
context.bit32 = bit32
context.bit = bit
context.pairs = pairs
context.ipairs = ipairs
Expand Down
4 changes: 2 additions & 2 deletions modules/game_healthinfo/healthinfo.lua
Original file line number Diff line number Diff line change
Expand Up @@ -230,11 +230,11 @@ end
function onStatesChange(localPlayer, now, old)
if now == old then return end

local bitsChanged = bit32.bxor(now, old)
local bitsChanged = bit.bxor(now, old)
for i = 1, 32 do
local pow = math.pow(2, i-1)
if pow > bitsChanged then break end
local bitChanged = bit32.band(bitsChanged, pow)
local bitChanged = bit.band(bitsChanged, pow)
if bitChanged ~= 0 then
toggleIcon(bitChanged)
end
Expand Down
4 changes: 2 additions & 2 deletions modules/game_inventory/inventory.lua
Original file line number Diff line number Diff line change
Expand Up @@ -475,11 +475,11 @@ end

function onStatesChange(localPlayer, now, old)
if now == old then return end
local bitsChanged = bit32.bxor(now, old)
local bitsChanged = bit.bxor(now, old)
for i = 1, 32 do
local pow = math.pow(2, i-1)
if pow > bitsChanged then break end
local bitChanged = bit32.band(bitsChanged, pow)
local bitChanged = bit.band(bitsChanged, pow)
if bitChanged ~= 0 then
toggleIcon(bitChanged)
end
Expand Down
2 changes: 1 addition & 1 deletion modules/game_ruleviolation/ruleviolation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function onSelectReason(reasonLabel, focused)
actionsTextList:destroyChildren()
for actionBaseFlag = 0, #rvactions do
local actionFlagString = rvactions[actionBaseFlag]
if bit32.band(reasonLabel.actionFlags, math.pow(2, actionBaseFlag)) > 0 then
if bit.band(reasonLabel.actionFlags, math.pow(2, actionBaseFlag)) > 0 then
local label = g_ui.createWidget('RVListLabel', actionsTextList)
label:setText(actionFlagString)
label.actionId = actionBaseFlag
Expand Down
4 changes: 2 additions & 2 deletions modules/game_topbar/topbar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -292,11 +292,11 @@ end
function onStatesChange(localPlayer, now, old)
if now == old then return end

local bitsChanged = bit32.bxor(now, old)
local bitsChanged = bit.bxor(now, old)
for i = 1, 32 do
local pow = math.pow(2, i - 1)
if pow > bitsChanged then break end
local bitChanged = bit32.band(bitsChanged, pow)
local bitChanged = bit.band(bitsChanged, pow)
if bitChanged ~= 0 then toggleIcon(bitChanged) end
end
end
Expand Down
2 changes: 1 addition & 1 deletion modules/gamelib/player.lua
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ function Player:hasState(state, states)
local pow = math.pow(2, i-1)
if pow > states then break end

local states = bit32.band(states, pow)
local states = bit.band(states, pow)
if states == state then
return true
end
Expand Down
8 changes: 4 additions & 4 deletions src/framework/luaengine/lbitlib.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* This is the bit32 library from lua 5.2.0, backported to
* This is the bit library from lua 5.2.0, backported to
* lua 5.1.4.
*
* version 5.2.0-backport4
Expand Down Expand Up @@ -164,9 +164,9 @@ static lua_Unsigned luaL_checkunsigned (lua_State *L, int arg) {
/* ----- Lua 5.2 luaL_newlib() compatibility: ----- */

#define LUAMOD_API LUALIB_API
#define LUA_BIT32LIBNAME "bit32"
#define LUA_BITLIBNAME "bit"
#ifndef luaL_newlib
#define luaL_newlib(x, y) luaL_register(x, LUA_BIT32LIBNAME, y)
#define luaL_newlib(x, y) luaL_register(x, LUA_BITLIBNAME, y)
#endif

/* ----- avoid a 'symbol redefined' warning below ----- */
Expand Down Expand Up @@ -372,7 +372,7 @@ static const luaL_Reg bitlib[] = {
{NULL, NULL}
};

int luaopen_bit32 (lua_State *L) {
int luaopen_bit (lua_State *L) {
luaL_newlib(L, bitlib);
return 1;
}
Expand Down
2 changes: 1 addition & 1 deletion src/framework/luaengine/lbitlib.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@

struct lua_State;

int luaopen_bit32 (lua_State *L);
int luaopen_bit (lua_State *L);

#endif
4 changes: 2 additions & 2 deletions src/framework/luaengine/luainterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -738,8 +738,8 @@ void LuaInterface::createLuaState()
// load lua standard libraries
luaL_openlibs(L);

// load bit32 lib for bitwise operations
luaopen_bit32(L);
// load bit lib for bitwise operations
luaopen_bit(L);

// creates weak table
newTable();
Expand Down

0 comments on commit a6a4669

Please sign in to comment.