Lua:synchronize

From Cheat Engine
Revision as of 20:54, 26 June 2026 by Leunsel (talk | contribs) (Added related function template.)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

<> Lua API Reference

function synchronize(function, ...) : any

Calls the given function from the main thread.

Any additional arguments are passed to the function when it is called. The return value of the given function is returned by synchronize.

Function Parameters

Parameter Type Description
function Function The function to call from the main thread.
... Any (optional) Additional arguments that are passed to the function.

Returns

any — The return value of the given function.

Examples

1 local result = synchronize(function()
2   return getMainForm().Caption
3 end)
4 
5 print(result)
1 local function add(a, b)
2   return a + b
3 end
4 
5 local result = synchronize(add, 10, 20)
6 
7 print(result)
 1 function ShowError(message)
 2     if not inMainThread() then
 3         synchronize(function()
 4             self:ShowError(message)
 5         end)
 6         return
 7     end
 8     messageDialog(message, mtError, mbOK)
 9 end
10 
11 ShowError("Some Error!")

Main Pages

Core Lua documentation entry points

Lua
Script Engine

Thread Related Lua Functions

CPU information, process threads, main-thread execution, and queued callbacks