CompileString
Example
Code that will not compile, with ErrorHandling set to false.
Output: TestCode:1: unfinished string near '<eof>' (this is not a script error - it is a returned string)
Example
Code that will compile.
local code = "MsgN('Hi')"
local func = CompileString(code, "TestCode")
if func then -- Compile String returns nil if 3rd argument is true and code has errors.
func()
end
Output: Hi
Example
Compiled code with custom arguments; captured with the varargs identifier.
local code = [[
local args = { ... }
print( unpack( args ) )
print( args[ 2 ] + args[ 3 ])
print( args[ 4 ] .. args[ 5 ])
local first, second = ...
print( first, second )
]]
local func = CompileString( code, "VarargCodeTest" )
func( 1, 2, 3, "A", "B", "C" )
Output:
1 2 3 A B C
5
AB
1 2