Returns a compiled string as a function.
loadstring (string [, chunkname])
Parameters[]
Arguments[]
- string
- string - String to be compiled.
- chunkname
- string - chunkname is used as the string's designation for error messages and debug information. When absent, it defaults to "=(load)".
Returns[]
- function
- function - If there are no errors, returns the compiled string as a function; otherwise, returns nil. The environment of the returned function is the global environment.
- error
- string - If there are no errors, returns nothing; otherwise, returns the error message.
Example[]
Runtime Error - This example returns a function, but that function throws an error when called:
local f, err = loadstring("SitOrStanddddd()", "Runtime Error Sit or Stand");
if ( f ) then
f();
else
DEFAULT_CHAT_FRAME:AddMessage(err,1,0,0);
end
Compile Time Error - This returns nil and an error string, but the error is not propagated, and is printed to the chat frame:
local f, err= loadstring("iffffff true then SitOrStand() end", "Compile Time Error Sit String");
if ( f ) then
f();
else
DEFAULT_CHAT_FRAME:AddMessage(err,1,0,0);
end
No Errors - This example returns a function, and causes your character to sit or stand:
local f, err= loadstring("SitOrStand()", "Working Sit or Stand");
if ( f ) then
f();
else
DEFAULT_CHAT_FRAME:AddMessage(err,1,0,0);
end