WoW:API loadstring: Difference between revisions

{{luaapi}}
mNo edit summary
({{luaapi}})
Line 1: Line 1:
{{luaapi}}
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 ==
=== Parameters ===
;luaCodeBlock:String - a string of Lua code. Can be very long.
:;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...'']".
:;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
;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.
;errorMessage:String - will contain an error message if ''func'' was nil.


== Examples ==
== Examples ==
Line 77: Line 77:


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.
{{LUA}}