loadstring

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)

function loadstring<A...>(src: string, chunkname: string?): ((A...) -> any | nil, string?)

Parameters

  • src - The source to compile.

  • chunkname - Name of the chunk.


Examples

loadstring([[
    Placeholder = {"Example"}
]])()

print(Placeholder[1]) -- Output: Example
local Func, Err = loadstring("Example = ", "CustomName")

print(`{Func}, {Err}`) -- Output: nil, [string "CustomName"]:1: Expected identifier when parsing expression, got <eof>

Last updated