Lua:synchronize

From Cheat Engine
Revision as of 04:45, 21 June 2026 by Leunsel (talk | contribs)
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

local result = synchronize(function()
  return getMainForm().Caption
end)

print(result)
local function add(a, b)
  return a + b
end

local result = synchronize(add, 10, 20)

print(result)
function ShowError(message)
    if not inMainThread() then
        synchronize(function()
            self:ShowError(message)
        end)
        return
    end
    messageDialog(message, mtError, mbOK)
end

ShowError("Some Error!")

Main Pages

Core Lua documentation entry points

Lua
Script Engine

See also