-- 语法错误会让整个文件都无法运行,所以用 load 单独编译代码;
-- = 是赋值,== 是比较
local chunk1, err1 = load("if x = 0 then end")
-- chunk1 = nil
-- err1 = [string "if x = 0 then end"]:1:
-- 'then' expected near '='
-- 缺少 then 也会同样被发现
local chunk2, err2 = load("if x == 0 end")
-- err2 = [string "if x == 0 end"]:1:
-- 'then' expected near 'end'
-- 正确的写法可以编译
local chunk3 = load("if x == 0 then end")
-- type(chunk3) = function
print("chunk1 = " .. tostring(chunk1))
print("err1 = " .. err1)
print("err2 = " .. err2)
print("type(chunk3) = " .. type(chunk3))