WoW:API pcall: Difference between revisions

From AddOn Studio
Jump to navigation Jump to search
(Change category from "LUA Functions" to "Lua functions".)
Line 1: Line 1:
<center>'''pcall''' ''-Documentation by [[user:Darjk|Darjk]]-''</center>
<center>'''pcall''' ''-Documentation by [[user:Darjk|Darjk]]-''</center>
Native Lua statement:


Returns a boolean value to catch errors from the function call (func).
Returns a boolean value to catch errors from the function call (func).
Line 35: Line 37:
: pcall will ''also'' return other arguments returned from the "function" if all is successful.
: pcall will ''also'' return other arguments returned from the "function" if all is successful.


----
{{LUA}}
__NOTOC__
{{Template:WoW API}}

Revision as of 12:15, 26 May 2006

pcall -Documentation by Darjk-

Native Lua statement:

Returns a boolean value to catch errors from the function call (func).

retVal = pcall (func, arg1, arg2, ...);

Parameters

Arguments

(func, arg1, arg2, ...)
func
Function - The function that will be called (from within) pcall().
arg1
Variable - Any variable that is also to be passed with the function when its called (if any).
arg2
Variable - Same as arg1.

Returns

Returns
retVal
retvaL
Boolean - If the call to the function (that was passed to pcall) succeeded, returns true. If an error occured, returns false.

Example

function myTest()
  local strTest = "I am a string";
  strTest = strTest + 10;
end

local retVal = pcall(myTest);

Result

pcall will catch the error that occured within 'myTest' and return false.

retVal = false;

Details

pcall will also return other arguments returned from the "function" if all is successful.

Template:LUA