loadstring
Unsafe by design
Compiles the given string, and returns it runnable in a function. The environment must become unsafe after this function is called due to it allowing the modification of globals uncontrollably (see setfenv/getfenv documentation).
Notes on loadstring
If the source compiles sucecssfully, you will get a runnable function that, when called, will execute the source you provided along with the passed arguments. If the source fails to compile, you will instead receive nil
alongside the error, explaining what went wrong.
Parameters
Parameter | Description |
---|---|
source |
The source code string to compile. |
chunkname? |
Custom chunk name. |
Examples
Example 1
Compiling and running source code successfully | |
---|---|