Difference between revisions of "Pcall"

From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2011.6<br/> === Description === Calls function f with the given arguments in protected mode. This means that any error inside f is not...")
 
Line 4: Line 4:
 
Calls function f with the given arguments in protected mode. This means that any error inside f is not propagated; instead, `pcall` catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, `pcall` also returns all results from the call, after this first result. In case of any error, `pcall` returns false plus the error message.
 
Calls function f with the given arguments in protected mode. This means that any error inside f is not propagated; instead, `pcall` catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, `pcall` also returns all results from the call, after this first result. In case of any error, `pcall` returns false plus the error message.
 
<source lang="lua">
 
<source lang="lua">
(bool) (any), = pcall(farg1arg2...,)
+
(bool), (any) = pcall(f,arg1,arg2,...)
 
</source>
 
</source>
'''f:''' (function) function to call in protected mode ''''''<br/>
+
'''f''': (function) function to call in protected mode ''''''<br/>
'''arg1:''' (any) argument to pass to the function '''optional'''<br/>
+
'''arg1''': (any) argument to pass to the function '''optional'''<br/>
'''arg2:''' (any) argument to pass to the function '''optional'''<br/>
+
'''arg2''': (any) argument to pass to the function '''optional'''<br/>
'''...:''' (any) other optional arguments '''optional'''<br/>
+
'''...''': (any) other optional arguments '''optional'''<br/>
 
'''Returns''' (bool) false if there was error, true if function call succeeded<br/>
 
'''Returns''' (bool) false if there was error, true if function call succeeded<br/>
 
'''Returns''' (any) all the results that function returns<br/>
 
'''Returns''' (any) all the results that function returns<br/>

Revision as of 11:20, 23 August 2018

Available since: Gideros 2011.6

Description

Calls function f with the given arguments in protected mode. This means that any error inside f is not propagated; instead, `pcall` catches the error and returns a status code. Its first result is the status code (a boolean), which is true if the call succeeds without errors. In such case, `pcall` also returns all results from the call, after this first result. In case of any error, `pcall` returns false plus the error message.

(bool), (any) = pcall(f,arg1,arg2,...)

'f: (function) function to call in protected mode '
arg1: (any) argument to pass to the function optional
arg2: (any) argument to pass to the function optional
...: (any) other optional arguments optional
Returns (bool) false if there was error, true if function call succeeded
Returns (any) all the results that function returns