示例工程 05-variables-and-scope

05-variables-and-scope/04-undefined-global-silent/main.lua

lua · 0.5 KB

-- @runtimes lua54 luajit
--- 演示:写错全局名不会报错,只会静默创建新全局。
 
local M = {}
 
--- @return table { expected = integer, got_nil = boolean }
function M.run(log)
	log = log or print
	_ = 0
	ghost = 1
	local expected = 2
	conut = expected + 1
	log(("count_is_nil=%s"):format(tostring(count == nil)))
	log(("ghost=%d"):format(ghost))
	return { expected = expected, got_nil = count == nil }
end
 
if not ... then
	M.run()
end
 
return M