API RunScript

104,672pages on
this wiki
Add New Page
Talk4 Share
WoW API < RunScript

Execute a string as LUA code.


Parameters Edit

Arguments Edit

string - code to be executed

Returns Edit


Example Edit

To define a function dynamically you could do:
local retExpr = '"Hello " .. UnitName("target")';
RunScript("function My_GetGreeting() return " .. retExpr .. ";end");

Result Edit

The My_GetGreeting() function will be defined to return Hello followed by the name of your target.

Details Edit

This function is NOT recommended for general use within addons for a number of reasons:
1. It'll do whatever you tell it, that includes calling functions, setting variables, whatever.
2. Errors in the script string produce the error popup (at least, they produce the UI_ERROR_MESSAGE event).
On the other hand, it's invaluable if you need to run code that is input by the player at run-time, or do self-generating code.

See Also Edit

  • The standard Lua function API loadstring, which can overcome all of the problems of RunScript described above.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.

Also on Fandom

Random Wiki