Difference between revisions of "Lua:bOr"
Jump to navigation
Jump to search
(Major overhaul of the post.) |
|||
| (One intermediate revision by one other user not shown) | |||
| Line 1: | Line 1: | ||
| − | + | [[Category:Lua]] | |
| + | '''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 (<code>|</code>) inside Cheat Engine. It is typically used when combining bitmasks or ensuring specific bits are set. | ||
| + | |||
| + | === Function Parameters === | ||
| + | {|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0" | ||
| + | !align="left"|Parameter | ||
| + | !align="left"|Type | ||
| + | !style="width: 80%;" align="left"|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 <code>int1</code>. | ||
| + | |} | ||
| + | |||
| + | === Returns === | ||
| + | An integer representing the result of the bitwise OR operation. | ||
| + | |||
| + | === Description === | ||
| + | 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:''' | ||
| + | |||
| + | <pre> | ||
| + | 0001 (1) | ||
| + | 0010 (2) | ||
| + | ---- | ||
| + | 0011 (3) | ||
| + | </pre> | ||
| + | |||
| + | === Usage Examples === | ||
| + | '''Simple bitwise OR:''' | ||
| + | |||
| + | <pre> | ||
| + | print( bOr(1, 2) ) -- 3 | ||
| + | </pre> | ||
| + | |||
| + | '''Using Lua's OR operator (equivalent):''' | ||
| + | |||
| + | <pre> | ||
| + | print( 1 | 2 ) -- 3 | ||
| + | </pre> | ||
| + | |||
| + | '''Combining bitmask flags:''' | ||
| + | |||
| + | <pre> | ||
| + | local FLAG_A = 0x01 | ||
| + | local FLAG_B = 0x04 | ||
| + | local combined = bOr(FLAG_A, FLAG_B) | ||
| + | print(string.format("0x%X", combined)) -- 0x5 | ||
| + | </pre> | ||
| + | |||
| + | '''Applying OR to set bits:''' | ||
| + | |||
| + | <pre> | ||
| + | local value = 0x10 | ||
| + | value = bOr(value, 0x02) -- Set bit 1 | ||
| + | print(string.format("0x%X", value)) | ||
| + | </pre> | ||
| + | |||
| + | === Behavior === | ||
| + | |||
| + | * Always returns an integer. | ||
| + | * Only works on numeric values; non-integer types should be converted beforehand. | ||
| + | * Equivalent to the native bitwise OR operator (<code>|</code>) in Cheat Engine's Lua. | ||
| + | |||
| + | === Advanced Examples === | ||
| + | '''Using OR to toggle feature flags:''' | ||
| + | |||
<pre> | <pre> | ||
| − | + | local FEATURE_RENDER = 0x01 | |
| − | + | local FEATURE_PHYSICS = 0x02 | |
| + | local enabled = 0 | ||
| − | + | -- Enable rendering | |
| − | + | enabled = bOr(enabled, FEATURE_RENDER) | |
| − | ---- | + | -- Enable physics |
| − | + | enabled = bOr(enabled, FEATURE_PHYSICS) | |
| + | |||
| + | print(enabled) -- 3 | ||
</pre> | </pre> | ||
| + | |||
| + | '''Combining OR with bitwise AND for flag management:''' | ||
| + | |||
| + | <pre> | ||
| + | local flags = 0 | ||
| + | flags = bOr(flags, 0x08) -- Enable bit 3 | ||
| + | if (flags & 0x08) ~= 0 then | ||
| + | print("Bit 3 enabled") | ||
| + | end | ||
| + | </pre> | ||
| + | |||
| + | === See Also === | ||
| + | |||
| + | * [[Lua:bOr|bOr]] - Bitwise OR | ||
| + | * [[Lua:bXor|bXor]] - Bitwise XOR | ||
| + | * [[Lua:bAnd|bAnd]] - Bitwise AND | ||
| + | * [[Lua:bShl|bShl]] - Bitwise Shift Left | ||
| + | * [[Lua:bShr|bShr]] - Bitwise Shift Right | ||
| + | * [[Lua:bNot|bNot]] - Bitwise NOT | ||
Latest revision as of 14:46, 3 December 2025
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.
Contents
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:
print( bOr(1, 2) ) -- 3
Using Lua's OR operator (equivalent):
print( 1 | 2 ) -- 3
Combining bitmask flags:
local FLAG_A = 0x01
local FLAG_B = 0x04
local combined = bOr(FLAG_A, FLAG_B)
print(string.format("0x%X", combined)) -- 0x5
Applying OR to set bits:
local value = 0x10
value = bOr(value, 0x02) -- Set bit 1
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:
local FEATURE_RENDER = 0x01 local FEATURE_PHYSICS = 0x02 local enabled = 0 -- Enable rendering enabled = bOr(enabled, FEATURE_RENDER) -- Enable physics enabled = bOr(enabled, FEATURE_PHYSICS) print(enabled) -- 3
Combining OR with bitwise AND for flag management:
local flags = 0
flags = bOr(flags, 0x08) -- Enable bit 3
if (flags & 0x08) ~= 0 then
print("Bit 3 enabled")
end