m
Move page script moved page API loadstring to WoW:API loadstring without leaving a redirect
(yank divs, fix headers) |
m (Move page script moved page API loadstring to WoW:API loadstring without leaving a redirect) |
||
| (3 intermediate revisions by 3 users not shown) | |||
| Line 1: | Line 1: | ||
{{ | {{wowlua}} | ||
Parse a string as Lua code and return it as a reference to a function. | Parse a string as Lua code and return it as a reference to a function. | ||
func, errorMessage = loadstring("luaCodeBlock"[, "chunkName"]); | func, errorMessage = loadstring("luaCodeBlock"[, "chunkName"]); | ||
== Arguments == | == Arguments == | ||
;luaCodeBlock | |||
:String - a string of Lua code. Can be very long. | |||
;chunkName | |||
:String - optionally name the code block. Will be shown as the "file name" in error messages. If not given, the file name will be "[string: ''first line of your Lua code here...'']". | |||
=== Returns === | === Returns === | ||
;func | |||
:Function reference - nil if there was a syntax error in the code block | |||
;errorMessage | |||
:String - will contain an error message if ''func'' was nil. | |||
== Examples == | == Examples == | ||
| Line 21: | Line 24: | ||
=== Catching all errors === | === Catching all errors === | ||
local func, errorMessage = loadstring("DEFAULT_CHAT_FRAME:AddMessage(\"Hello, World!\")"); | local func, errorMessage = loadstring("DEFAULT_CHAT_FRAME:AddMessage(\"Hello, World!\")"); | ||
if(not func) then | if(not func) then | ||
| Line 78: | Line 81: | ||
Will result in "meaning_of_life_the_universe_and_everything" containing the number 42. | Will result in "meaning_of_life_the_universe_and_everything" containing the number 42. | ||