View Single Post
07-19-21, 09:09 AM   #5
Zax
A Flamescale Wyrmkin
AddOn Author - Click to view addons
Join Date: Aug 2006
Posts: 147
Originally Posted by Fizzlemizz View Post
or are you saying you want to test if RunScript(strLine) is going to run without error before running RunScript(strLine)?
Yes

If I write RunScript("mmmkkhgrttt") I will have a lua error, and I would like to trap this error.
In fact, I'm now able to do this with something like:
Lua Code:
  1. local func, errorMessage = loadstring(strLine)
  2.             if (not func) then
  3.                 isError = true
  4.             else
  5.                 local success, errorMessage = pcall(func)
  6.                 if (not success) then
  7.                     isError = true
  8.                 end
  9.             end

The tricky part is to catch errors when a macro is passed to the function .executeCmd() and processed with:
Lua Code:
  1. if (isMacroBoolean)) then
  2.                 --------------------------- macro ("/" needed)
  3.                 if (string.sub(strLine, 1, 1) ~= "/") then strLine = "/"..strLine end
  4.                 DEFAULT_CHAT_FRAME.editBox:SetText(strLine)
  5.                 ChatEdit_SendText(DEFAULT_CHAT_FRAME.editBox, 0)
  6.             else
  7.                 ...
  8.             end
In case of macro passed as strLine, I don't know how to test/try strLine.
__________________
Zax - Addons List, not all maintained.
  Reply With Quote