--禁用默认全局变量 -- export global variable local __g = _G BF = BF or {} BF.exports = BF.exports or {} setmetatable(BF.exports, { __newindex = function(_, name, value) rawset(__g, name, value) end, __index = function(_, name) return rawget(__g, name) end }) -- disable create unexpected global variable local function disableGlobal() setmetatable(__g, { __newindex = function(_, name, value) print("new index, name is :", name) error(string.format("USE \" BF.exports.%s = value \" INSTEAD OF SET GLOBAL VARIABLE", name), 0) end }) end BF.disableGlobal = disableGlobal disableGlobal()