Example
Code that will not compile, with ErrorHandling set to false.
local code
= "MsgN('Hi)"
local func
= CompileString(code,
"TestCode",
false)
MsgN(func)
Output: TestCode:1: unfinished string near '<eof>' (this is not a script error - it is a returned string)
Example
local code
= "MsgN('Hi')"
local func
= CompileString(code,
"TestCode")
if func
then
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