Thread Tools Display Modes
01-27-06, 11:14 AM   #1
wereHamster
A Black Drake
 
wereHamster's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 80
RunScript() and pcall()

pcall (f, arg1, arg2, ...)
Calls function f with the given arguments in protected mode. That 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.
The following code thorws an error (makes the error-frame pop up), but it should fail silently:
Code:
pcall(RunScript, "asdf")
Even this works as it should, eg. fails silently without the error popup window:
Code:
pcall(error, "asdf")

Can anyone convince the developers to properly implement RunScript()? or maybe even add loadstring()?

Basically RunScript() is loadstring() without the error-checking code, I don't understand why blizzard did that

I've started a thread in the european forums, but no blue answer yet

http://forums-en.wow-europe.com/thre...ThreadID=31803



Does anyone know a workaround for this?

Last edited by wereHamster : 01-27-06 at 11:18 AM.
  Reply With Quote
01-27-06, 01:27 PM   #2
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Basically RunScript() is loadstring() without the error-checking code, I don't understand why blizzard did that
I think you mean: RunScript() is loadstring() with added error catching and throwing code.

Can you hook _ERRORMESSAGE, does it help?
  Reply With Quote
01-27-06, 01:34 PM   #3
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
I've posted a request on the US forums, hopefully slouken will respond.

http://forums.worldofwarcraft.com/th...hreadID=309903

Look at that palindromic thread ID, It's a sign!
  Reply With Quote
01-27-06, 01:54 PM   #4
Cladhaire
Salad!
 
Cladhaire's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Jul 2005
Posts: 1,935
Wow.. is it sad that you posted about it, or sad that I noticed it before i finished reading =)
__________________
"There's only one thing that I know how to do well and I've often been told that you only can do what you know how to do well, and that's be you-- be what you're like-- be like yourself. And so I'm having a wonderful time, but I'd rather be whistling in the dark..."
  Reply With Quote
01-27-06, 01:59 PM   #5
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Originally Posted by Iriel
I've posted a request on the US forums, hopefully slouken will respond.

http://forums.worldofwarcraft.com/th...hreadID=309903

Look at that palindromic thread ID, It's a sign!
We'll have loadstring in 1.10! Yay!
  Reply With Quote
01-27-06, 02:52 PM   #6
wereHamster
A Black Drake
 
wereHamster's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2006
Posts: 80
Originally Posted by Iriel
We'll have loadstring in 1.10! Yay!
Thank you very much, I'm very happy... but also a bit sad because nobody reads the european forums, I mean nobody like slouken, or someone else who would be competent enough to respond to our questions.

about the _ERRORMESSAGE hook, thanks about the hint, I didn't know there was something like that, but loadstring() is significantly different that RunScript() because it doesn't run the code, it returns a function with the parsed string as function body.

I'm using the following code to get around this, but that still fails if the string can't be parsed properly, setfenv() is there to make sure that the argString doesn't contain any function calls

Code:
RunScript("argFunc = function() return "..argString.." end")
							
if (argFunc) then
  setfenv(argFunc, { })
  local argList = { pcall(argFunc) }
  if (argList[1]) then
    argList[1] = moduleObject
    moduleObject[moduleFunction](unpack(argList))
  end
  argFunc = nil
end
btw, this is code from commChannels ( http://www.curse-gaming.com/mod.php?addid=2606 )
  Reply With Quote
01-27-06, 02:59 PM   #7
Iriel
Super Moderator
WoWInterface Super Mod
Featured
Join Date: Jun 2005
Posts: 578
Originally Posted by Shag
Thank you very much, I'm very happy... but also a bit sad because nobody reads the european forums, I mean nobody like slouken, or someone else who would be competent enough to respond to our questions.

about the _ERRORMESSAGE hook, thanks about the hint, I didn't know there was something like that, but loadstring() is significantly different that RunScript() because it doesn't run the code, it returns a function with the parsed string as function body.
I suspect that internally RunScript is similar to the assert(loadstring(x))() example given in the LUA documentation.

Last edited by Iriel : 01-27-06 at 03:02 PM.
  Reply With Quote

WoWInterface » AddOns, Compilations, Macros » AddOn Search/Requests » RunScript() and pcall()


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off