From a6a4669d084ebac28bd63ea51d71c9e1ccc65d98 Mon Sep 17 00:00:00 2001 From: ALYSON FARIA JACOMINE Date: Sun, 23 Feb 2025 08:03:45 -0300 Subject: [PATCH] Fix change all uses "bit32" for "bit" This modification is necessary due to the LIB update. Fix compilation warnings and LUA errors in the otclient console. --- modules/corelib/base64.lua | 4 ++-- modules/corelib/keyboard.lua | 6 +++--- modules/game_bot/executor.lua | 1 - modules/game_healthinfo/healthinfo.lua | 4 ++-- modules/game_inventory/inventory.lua | 4 ++-- modules/game_ruleviolation/ruleviolation.lua | 2 +- modules/game_topbar/topbar.lua | 4 ++-- modules/gamelib/player.lua | 2 +- src/framework/luaengine/lbitlib.cpp | 8 ++++---- src/framework/luaengine/lbitlib.h | 2 +- src/framework/luaengine/luainterface.cpp | 4 ++-- 11 files changed, 20 insertions(+), 21 deletions(-) diff --git a/modules/corelib/base64.lua b/modules/corelib/base64.lua index c220f4ba..c4eb596c 100644 --- a/modules/corelib/base64.lua +++ b/modules/corelib/base64.lua @@ -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 @@ -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 diff --git a/modules/corelib/keyboard.lua b/modules/corelib/keyboard.lua index 463fe1ee..c90e700c 100644 --- a/modules/corelib/keyboard.lua +++ b/modules/corelib/keyboard.lua @@ -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 diff --git a/modules/game_bot/executor.lua b/modules/game_bot/executor.lua index 0ca87a93..3e959ba1 100644 --- a/modules/game_bot/executor.lua +++ b/modules/game_bot/executor.lua @@ -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 diff --git a/modules/game_healthinfo/healthinfo.lua b/modules/game_healthinfo/healthinfo.lua index 3ac4ea4b..43a991ce 100644 --- a/modules/game_healthinfo/healthinfo.lua +++ b/modules/game_healthinfo/healthinfo.lua @@ -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 diff --git a/modules/game_inventory/inventory.lua b/modules/game_inventory/inventory.lua index b50a6804..dea9fb6d 100644 --- a/modules/game_inventory/inventory.lua +++ b/modules/game_inventory/inventory.lua @@ -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 diff --git a/modules/game_ruleviolation/ruleviolation.lua b/modules/game_ruleviolation/ruleviolation.lua index 156fdded..06500602 100644 --- a/modules/game_ruleviolation/ruleviolation.lua +++ b/modules/game_ruleviolation/ruleviolation.lua @@ -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 diff --git a/modules/game_topbar/topbar.lua b/modules/game_topbar/topbar.lua index cf749e0d..30a4243b 100644 --- a/modules/game_topbar/topbar.lua +++ b/modules/game_topbar/topbar.lua @@ -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 diff --git a/modules/gamelib/player.lua b/modules/gamelib/player.lua index 5fcc6e85..7c6489d7 100644 --- a/modules/gamelib/player.lua +++ b/modules/gamelib/player.lua @@ -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 diff --git a/src/framework/luaengine/lbitlib.cpp b/src/framework/luaengine/lbitlib.cpp index 48c2e1ab..d97df38b 100644 --- a/src/framework/luaengine/lbitlib.cpp +++ b/src/framework/luaengine/lbitlib.cpp @@ -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 @@ -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 ----- */ @@ -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; } diff --git a/src/framework/luaengine/lbitlib.h b/src/framework/luaengine/lbitlib.h index bb8f1ba5..7fe75012 100644 --- a/src/framework/luaengine/lbitlib.h +++ b/src/framework/luaengine/lbitlib.h @@ -25,6 +25,6 @@ struct lua_State; -int luaopen_bit32 (lua_State *L); +int luaopen_bit (lua_State *L); #endif diff --git a/src/framework/luaengine/luainterface.cpp b/src/framework/luaengine/luainterface.cpp index 70a2d95b..8c9e8335 100644 --- a/src/framework/luaengine/luainterface.cpp +++ b/src/framework/luaengine/luainterface.cpp @@ -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();