Difference between revisions of "Lua:synchronize"
Jump to navigation
Jump to search
m (Added related function template.) |
|||
| Line 25: | Line 25: | ||
===Examples=== | ===Examples=== | ||
| − | < | + | <syntaxhighlight lang="lua" line> |
local result = synchronize(function() | local result = synchronize(function() | ||
return getMainForm().Caption | return getMainForm().Caption | ||
| Line 31: | Line 31: | ||
print(result) | print(result) | ||
| − | </ | + | </syntaxhighlight> |
| − | < | + | <syntaxhighlight lang="lua" line> |
local function add(a, b) | local function add(a, b) | ||
return a + b | return a + b | ||
| Line 41: | Line 41: | ||
print(result) | print(result) | ||
| − | </ | + | </syntaxhighlight> |
| − | < | + | <syntaxhighlight lang="lua" line> |
function ShowError(message) | function ShowError(message) | ||
if not inMainThread() then | if not inMainThread() then | ||
| Line 55: | Line 55: | ||
ShowError("Some Error!") | ShowError("Some Error!") | ||
| − | </ | + | </syntaxhighlight> |
{{LuaSeeAlso}} | {{LuaSeeAlso}} | ||
| − | + | {{Threads}} | |
| − | |||
| − | |||
Latest revision as of 20:54, 26 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[edit]
| Parameter | Type | Description |
|---|---|---|
| function | Function | The function to call from the main thread. |
| ... | Any (optional) | Additional arguments that are passed to the function. |
Returns[edit]
any — The return value of the given function.
Examples[edit]
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!")