Difference between revisions of "Lua:synchronize"
Jump to navigation
Jump to search
(Created page with "Category:Lua '''function''' synchronize(''Function'', ...) ''':''' any Calls the given function from the main thread, passing any additional arguments. Returns the retu...") |
|||
| Line 1: | Line 1: | ||
[[Category:Lua]] | [[Category:Lua]] | ||
| − | '''function''' synchronize('' | + | {{CodeBox|'''function''' synchronize(''function'', ''...'') ''':''' any}} |
| − | Calls the given function from the main thread | + | 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=== | ===Function Parameters=== | ||
| Line 11: | Line 12: | ||
!style="width: 80%;background-color:white;" align="left"|Description | !style="width: 80%;background-color:white;" align="left"|Description | ||
|- | |- | ||
| + | |function | ||
|Function | |Function | ||
| − | + | |The function to call from the main thread. | |
| − | |The function to | ||
|- | |- | ||
|... | |... | ||
| − | |Any | + | |Any (optional) |
| − | | | + | |Additional arguments that are passed to the function. |
|} | |} | ||
===Returns=== | ===Returns=== | ||
| − | The return value | + | any — The return value of the given function. |
===Examples=== | ===Examples=== | ||
| + | <pre> | ||
| + | local result = synchronize(function() | ||
| + | return getMainForm().Caption | ||
| + | end) | ||
| + | |||
| + | print(result) | ||
| + | </pre> | ||
| + | |||
| + | <pre> | ||
| + | local function add(a, b) | ||
| + | return a + b | ||
| + | end | ||
| + | |||
| + | local result = synchronize(add, 10, 20) | ||
| + | |||
| + | print(result) | ||
| + | </pre> | ||
| + | |||
<pre> | <pre> | ||
function ShowError(message) | function ShowError(message) | ||
| Line 34: | Line 53: | ||
messageDialog(message, mtError, mbOK) | messageDialog(message, mtError, mbOK) | ||
end | end | ||
| + | |||
| + | ShowError("Some Error!") | ||
</pre> | </pre> | ||
| + | |||
| + | {{LuaSeeAlso}} | ||
== See also == | == See also == | ||
* [[Lua:inMainThread|inMainThread]] | * [[Lua:inMainThread|inMainThread]] | ||
* [[Lua:createThread|createThread]] | * [[Lua:createThread|createThread]] | ||
Revision as of 04:45, 21 June 2026
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!")