Lua SwitchScript

SwitchScript
Allows the currently executing script to be changed after the current execution cycle is over. This is NOT the same as the dofile or loadfile functions that are available generically with Lua. The effect of SwitchScript will not activate until AFTER the current cycle is complete, that means:

If SwitchScript is called from within the Main function, the current execution will still continue up until a return is made (the normal use of the return is discarded in this case, so you can return anything once SwitchScript has been called).

If you call SwitchScript from outside of the Main function, the script will continue to execute to the end and Main will NOT be called, instead the script will be switched.

Along with the two points above, this also means that calling SwitchScript multiple times (with the same or different values) will have no effect at all.

A final thing to note is that when the script is switched, the entire Lua environment is disposed and re-built, which means all variables, functions and globals defined in the script which called SwitchScript will be gone.

Arguments

 * (script)


 * script
 * The path of the Lua script to switch execution to.

Example
-- Running this script will randomly pick between two other scripts and -- switch to one of them once the current execution cycle is over.

function Main if math.random(2) == 1 then SwitchScript("EyeOfEternity.lua"); else SwitchScript("Naxxramas.lua"); end return nil; -- What we return here is irrelevent as we called SwitchScript. end