영어 위키백과>Jdforrester (WMF) m 1 revision imported from w:en:Module:No_globals: Page about technical change that was posted to a local wiki |
영어 위키백과>DannyS712 m Protected "Module:No globals": Highly visible template: Redundant to current transclusion on a cascading protected page, but better safe than sorry ([Edit=Allow only administrators] (indefinite) [Move=Allow only administrators] (indefinite)) |
(차이 없음)
| |
2019년 8월 30일 (금) 14:44 판
이 모듈은 nil 전역 변수를 읽거나 전역 변수 기록을 할 경우(arg 제외) 오류를 발생시킵니다. 모듈 최상단에 require('Module:No globals')를 추가하여 이 모듈을 사용할 수 있습니다. arg 변수가 제외되는 이유는 Scribunto의 require 함수가 정상 동작해야 하기 때문에 그렇습니다. (Scribunto 소스 코드는 여기를 참고)
local mt = getmetatable(_G) or {}
function mt.__index (t, k)
if k ~= 'arg' then
-- perf optimization here and below: do not load Module:TNT unless there is an error
error(require('Module:TNT').format('I18n/No globals', 'err-read', tostring(k)), 2)
end
return nil
end
function mt.__newindex(t, k, v)
if k ~= 'arg' then
error(require('Module:TNT').format('I18n/No globals', 'err-write', tostring(k)), 2)
end
rawset(t, k, v)
end
setmetatable(_G, mt)