维基百科,自由的百科全书
| 此模块被引用於約2,100,000個頁面。 為了避免造成大規模的影響,所有對此模块的編輯應先於沙盒或測試樣例上測試。 測試後無誤的版本可以一次性地加入此模块中,但是修改前請務必於討論頁發起討論。
模板引用數量會自動更新。 |
本模块将读取
空全域变量
和写入全局变量视为错误。
要使用本模块,
在模块
上方添加require('Module:No globals')
即可。
排除arg变量
是因为让 Scribunto
require功能正确运
行是必要的。(
在此参阅 Scribunto
代码。)
local mt = getmetatable(_G) or {}
function mt.__index (t, k)
if k ~= 'arg' then
error('尝试读取空全局变量:' .. tostring(k), 2)
end
return nil
end
function mt.__newindex(t, k, v)
if k ~= 'arg' then
error('尝试写入全局变量:' .. tostring(k), 2)
end
rawset(t, k, v)
end
setmetatable(_G, mt)