WoW:API RunScript: Difference between revisions
Jump to navigation
Jump to search
RunScript - Documentation by Flickering
m (New document) |
No edit summary |
||
Line 35: | Line 35: | ||
__NOTOC__ | __NOTOC__ | ||
{{Template:WoW API}} | {{Template:WoW API}} | ||
Revision as of 14:46, 4 January 2006
Execute a string as LUA code.
RunScript("script")
Parameters
Arguments
- ("script")
- script
- String - The code which is to be executed.
Returns
- nil
Example
- To define a function dynamically you could do:
local retExpr = '"Hello " .. UnitName("target")'; RunScript("function My_GetGreeting() return " .. retExpr .. ";end");
Result
- The My_GetGreeting() function will be defined to return Hello followed by the name of your target.
Details
- 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. It does things globally, so to get data out of it you have to pollute at least one global variable. This isn't a big deal but it's mildly annoying.
- 3. 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 arbitrary code, or do self-generating code.