Lua:errorOnLookupFailure
(Redirected from errorOnLookupFailure)
Jump to navigation
Jump to search
Controls whether address and symbol lookup failures raise an error.
If enabled, address lookups in string form will raise an error when the address cannot be resolved. This includes undefined symbols and invalid pointers.
If disabled, failed lookups return 0 instead. This is useful for pointers or symbols that may not be valid all the time.
By default, lookup failures raise an error.
Contents
- 1 Function Parameters
- 2 Returns
- 3 Examples
- 3.1 Disable lookup errors
- 3.2 Enable lookup errors
- 3.3 Use with an unstable pointer
- 3.4 Restore the default behavior after a safe lookup
- 3.5 Use getAddressSafe instead of changing the global behavior
- 3.6 Temporarily suppress lookup errors
- 3.7 Handle optional symbols
- 3.8 Avoid pointer lookup crashes in repeated checks
Function Parameters[edit]
| Parameter | Type | Description |
|---|---|---|
| state | Boolean | If true, lookup failures raise an error. If false, lookup failures return 0. |
Returns[edit]
This function does not return a value.
Examples[edit]
Disable lookup errors[edit]
1 errorOnLookupFailure(false)
Enable lookup errors[edit]
1 errorOnLookupFailure(true)
Use with an unstable pointer[edit]
1 errorOnLookupFailure(false)
2
3 local address = getAddress("[[[game.exe+1234]+10]+20]+30")
4
5 if address == 0 then
6 print("Pointer could not be resolved")
7 else
8 print(string.format("%X", address))
9 end
Restore the default behavior after a safe lookup[edit]
1 errorOnLookupFailure(false)
2
3 local address = getAddress("SomeOptionalSymbol")
4
5 if address == 0 then
6 print("Symbol not available")
7 end
8
9 -- Restore default behavior
10 errorOnLookupFailure(true)
Use getAddressSafe instead of changing the global behavior[edit]
1 local address = getAddressSafe("SomeOptionalSymbol")
2
3 if address == nil then
4 print("Symbol not available")
5 end
Temporarily suppress lookup errors[edit]
1 local function lookupOptionalAddress(symbol)
2 errorOnLookupFailure(false)
3
4 local address = getAddress(symbol)
5
6 errorOnLookupFailure(true)
7
8 if address == 0 then
9 return nil
10 end
11
12 return address
13 end
Handle optional symbols[edit]
1 errorOnLookupFailure(false)
2
3 local symbols = {
4 "OptionalSymbolA",
5 "OptionalSymbolB",
6 "OptionalSymbolC"
7 }
8
9 for i, symbol in ipairs(symbols) do
10 local address = getAddress(symbol)
11
12 if address ~= 0 then
13 print(symbol .. " = " .. string.format("%X", address))
14 end
15 end
16
17 errorOnLookupFailure(true)
Avoid pointer lookup crashes in repeated checks[edit]
1 errorOnLookupFailure(false)
2
3 local function checkPointer()
4 local address = getAddress("[[[game.exe+1234]+10]+20]+30")
5
6 if address == 0 then
7 return nil
8 end
9
10 return readInteger(address)
11 end
12
13 errorOnLookupFailure(true)