FANDOM


Returns a compiled string as a function.

loadstring (string [, chunkname])

Parameters Edit

Arguments Edit

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 Edit

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 Edit

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

Notes Edit

Related Functions Edit

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.