Difference between revisions of "Lua:getAddressSafe"

From Cheat Engine
Jump to navigation Jump to search
m (Reverted edits by This content is not available (Talk) to last revision by TheyCallMeTim13)
m (Added related function template.)
 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
'''function''' getAddressSafe(''AddressString'', ''local'' OPTIONAL) ''':''' integer
+
{{CodeBox|'''function''' getAddressSafe(''symbolname'', ''local'', ''shallow'') ''':''' integer}}
  
Passes the given string to Cheat Engine's symbol handler and returns the corresponding address as an integer, or nil if not found. Similar to [[Lua:getAddress|getAddress]] when errorOnLookup is false, but returns nil instead. Can be a module name or an export. Set ''local'' to true if you wish to query the symbol table of the CE process.
+
Returns the address of a symbol, or nil if the symbol could not be resolved.
 +
 
 +
This function is similar to using getAddress with errorOnLookup set to false, but returns nil instead of raising an error when the symbol is not found.
 +
 
 +
The symbol can be a registered symbol, a module name, or an exported symbol. Set ''local'' to true to query the symbol table of the Cheat Engine process instead of the currently opened target process.
  
 
===Function Parameters===
 
===Function Parameters===
{|width="85%" cellpadding="10%" cellpadding="5%" cellspacing="0" border="0"
+
{|width="85%" cellpadding="10%" cellspacing="0" border="0"
 
!align="left"|Parameter
 
!align="left"|Parameter
 
!align="left"|Type
 
!align="left"|Type
 
!style="width: 80%;background-color:white;" align="left"|Description
 
!style="width: 80%;background-color:white;" align="left"|Description
 
|-
 
|-
|AddressString
+
|symbolname
|[[CEAddressString]]
+
|String
|The AddressString to convert to an integer
+
|The symbol, module name, or exported symbol to resolve.
 
|-
 
|-
 
|local
 
|local
|Boolean
+
|Boolean (optional)
|Set to true if you wish to query the symbol table of the CE process
+
|If true, queries the symbol table of the Cheat Engine process.
 +
|-
 +
|shallow
 +
|Boolean (optional)
 +
|If true, performs a shallow lookup.
 
|}
 
|}
  
 +
===Returns===
 +
integer or nil — The resolved address of the given symbol, or nil if the symbol could not be found.
 +
 +
===Examples===
 +
<syntaxhighlight lang="lua" line>
 +
local address = getAddressSafe("KERNEL32.AddAtomA")
 +
 +
if address ~= nil then
 +
  print(string.format("%X", address))
 +
else
 +
  print("Symbol could not be resolved")
 +
end
 +
</syntaxhighlight>
  
 
{{LuaSeeAlso}}
 
{{LuaSeeAlso}}
  
=== Related Functions ===
+
{{Address}}
* [[Lua:getAddress|getAddress]]
 
* [[Lua:getNameFromAddress|getNameFromAddress]]
 
* [[Lua:getCommonModuleList|getCommonModuleList]]
 
* [[Lua:inModule|inModule]]
 
* [[Lua:inSystemModule|inSystemModule]]
 
* [[Lua:targetIs64Bit|targetIs64Bit]]
 
* [[Lua:enumModules|enumModules]]
 

Latest revision as of 22:48, 26 June 2026

<> Lua API Reference

function getAddressSafe(symbolname, local, shallow) : integer

Returns the address of a symbol, or nil if the symbol could not be resolved.

This function is similar to using getAddress with errorOnLookup set to false, but returns nil instead of raising an error when the symbol is not found.

The symbol can be a registered symbol, a module name, or an exported symbol. Set local to true to query the symbol table of the Cheat Engine process instead of the currently opened target process.

Function Parameters[edit]

Parameter Type Description
symbolname String The symbol, module name, or exported symbol to resolve.
local Boolean (optional) If true, queries the symbol table of the Cheat Engine process.
shallow Boolean (optional) If true, performs a shallow lookup.

Returns[edit]

integer or nil — The resolved address of the given symbol, or nil if the symbol could not be found.

Examples[edit]

1 local address = getAddressSafe("KERNEL32.AddAtomA")
2 
3 if address ~= nil then
4   print(string.format("%X", address))
5 else
6   print("Symbol could not be resolved")
7 end

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Symbol Related Lua Functions

Symbol lookup, address resolution, module checks, and lookup callbacks