Difference between revisions of "Lua:bOr"

From Cheat Engine
Jump to navigation Jump to search
m (Added CodeBox Template.)
m (Syntax Highlighting.)
 
Line 41: Line 41:
 
'''Simple bitwise OR:'''
 
'''Simple bitwise OR:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
print( bOr(1, 2) )  -- 3
 
print( bOr(1, 2) )  -- 3
</pre>
+
</syntaxhighlight>
  
 
'''Using Lua's OR operator (equivalent):'''
 
'''Using Lua's OR operator (equivalent):'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
print( 1 | 2 )        -- 3
 
print( 1 | 2 )        -- 3
</pre>
+
</syntaxhighlight>
  
 
'''Combining bitmask flags:'''
 
'''Combining bitmask flags:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local FLAG_A = 0x01
 
local FLAG_A = 0x01
 
local FLAG_B = 0x04
 
local FLAG_B = 0x04
 
local combined = bOr(FLAG_A, FLAG_B)
 
local combined = bOr(FLAG_A, FLAG_B)
 
print(string.format("0x%X", combined)) -- 0x5
 
print(string.format("0x%X", combined)) -- 0x5
</pre>
+
</syntaxhighlight>
  
 
'''Applying OR to set bits:'''
 
'''Applying OR to set bits:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local value = 0x10
 
local value = 0x10
 
value = bOr(value, 0x02)  -- Set bit 1
 
value = bOr(value, 0x02)  -- Set bit 1
 
print(string.format("0x%X", value))
 
print(string.format("0x%X", value))
</pre>
+
</syntaxhighlight>
  
 
=== Behavior ===
 
=== Behavior ===
Line 77: Line 77:
 
'''Using OR to toggle feature flags:'''
 
'''Using OR to toggle feature flags:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local FEATURE_RENDER = 0x01
 
local FEATURE_RENDER = 0x01
 
local FEATURE_PHYSICS = 0x02
 
local FEATURE_PHYSICS = 0x02
Line 88: Line 88:
  
 
print(enabled)  -- 3
 
print(enabled)  -- 3
</pre>
+
</syntaxhighlight>
  
 
'''Combining OR with bitwise AND for flag management:'''
 
'''Combining OR with bitwise AND for flag management:'''
  
<pre>
+
<syntaxhighlight lang="lua" line>
 
local flags = 0
 
local flags = 0
 
flags = bOr(flags, 0x08)  -- Enable bit 3
 
flags = bOr(flags, 0x08)  -- Enable bit 3
Line 98: Line 98:
 
   print("Bit 3 enabled")
 
   print("Bit 3 enabled")
 
end
 
end
</pre>
+
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
 
{{BinaryOps}}
 
{{BinaryOps}}

Latest revision as of 20:03, 25 June 2026

<> Reference

function bOr(int1, int2) : Integer

Performs a bitwise OR operation between two integer values. This function behaves the same as Lua's bitwise OR operator (|) inside Cheat Engine. It is typically used when combining bitmasks or ensuring specific bits are set.

Function Parameters[edit]

Parameter Type Description
int1 integer The first integer value to be used in the bitwise OR operation.
int2 integer The second integer value to be combined with int1.

Returns[edit]

An integer representing the result of the bitwise OR operation.

Description[edit]

The bitwise OR operation compares each bit of the two integers and sets the bit in the result to 1 if either corresponding bit is 1. This is commonly used for:

  • Combining bitmask flags
  • Setting specific bit values
  • Low-level memory and instruction manipulation

Binary breakdown example:

0001   (1)
0010   (2)
----
0011   (3)

Usage Examples[edit]

Simple bitwise OR:

1 print( bOr(1, 2) )   -- 3

Using Lua's OR operator (equivalent):

1 print( 1 | 2 )        -- 3

Combining bitmask flags:

1 local FLAG_A = 0x01
2 local FLAG_B = 0x04
3 local combined = bOr(FLAG_A, FLAG_B)
4 print(string.format("0x%X", combined)) -- 0x5

Applying OR to set bits:

1 local value = 0x10
2 value = bOr(value, 0x02)   -- Set bit 1
3 print(string.format("0x%X", value))

Behavior[edit]

  • Always returns an integer.
  • Only works on numeric values; non-integer types should be converted beforehand.
  • Equivalent to the native bitwise OR operator (|) in Cheat Engine's Lua.

Advanced Examples[edit]

Using OR to toggle feature flags:

 1 local FEATURE_RENDER = 0x01
 2 local FEATURE_PHYSICS = 0x02
 3 local enabled = 0
 4 
 5 -- Enable rendering
 6 enabled = bOr(enabled, FEATURE_RENDER)
 7 -- Enable physics
 8 enabled = bOr(enabled, FEATURE_PHYSICS)
 9 
10 print(enabled)   -- 3

Combining OR with bitwise AND for flag management:

1 local flags = 0
2 flags = bOr(flags, 0x08)   -- Enable bit 3
3 if (flags & 0x08) ~= 0 then
4   print("Bit 3 enabled")
5 end

See Also[edit]

Main Pages

Bitwise Related Lua Functions

bOr – Bitwise OR
bXor – Bitwise XOR
bAnd – Bitwise AND
bShl – Bitwise Shift Left
bShr – Bitwise Shift Right
bNot – Bitwise NOT