Difference between revisions of "Lua:inMainThread"

From Cheat Engine
Jump to navigation Jump to search
m (Minor edit. Added Version Notice Template.)
Line 1: Line 1:
 
[[Category:Lua]]
 
[[Category:Lua]]
 
{{VersionNotice|6.4+}}
 
{{VersionNotice|6.4+}}
'''function''' inMainThread() ''':''' Boolean
+
{{CodeBox|'''function''' inMainThread() ''':''' boolean}}
  
 
Returns true if the current code is running inside the main thread.
 
Returns true if the current code is running inside the main thread.
 +
 +
This function is available in Cheat Engine 6.4 and later.
  
 
===Function Parameters===
 
===Function Parameters===
None.
+
This function has no parameters.
  
 
===Returns===
 
===Returns===
Boolean true if running in the main thread, false otherwise.
+
boolean True if the current code is running inside the main thread, otherwise false.
  
 
===Examples===
 
===Examples===
 
<pre>
 
<pre>
function ShowError(message)
+
if inMainThread() then
    if not inMainThread() then
+
  print("Running in the main thread")
        synchronize(function()
+
else
            self:ShowError(message)
+
  print("Not running in the main thread")
        end)
 
        return
 
    end
 
    messageDialog(message, mtError, mbOK)
 
 
end
 
end
 
</pre>
 
</pre>
  
== See also ==
+
{{LuaSeeAlso}}
* [[Lua:createThread|createThread]]
 
* [[Lua:synchronize|synchronize]]
 

Revision as of 04:47, 21 June 2026

⚠️ Version Notice

This function requires Cheat Engine 6.4+.

<> Lua API Reference

function inMainThread() : boolean

Returns true if the current code is running inside the main thread.

This function is available in Cheat Engine 6.4 and later.

Function Parameters

This function has no parameters.

Returns

boolean — True if the current code is running inside the main thread, otherwise false.

Examples

if inMainThread() then
  print("Running in the main thread")
else
  print("Not running in the main thread")
end

Main Pages

Core Lua documentation entry points

Lua
Script Engine