m (판 2개를 가져왔습니다: 위키백과에서 가져옴) |
imported>MusikAnimal m (1 revision imported) |
||
2번째 줄: | 2번째 줄: | ||
function mt.__index (t, k) | function mt.__index (t, k) | ||
if k ~= 'arg' then | if k ~= 'arg' then | ||
error(' | -- 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 | end | ||
return nil | return nil | ||
8번째 줄: | 9번째 줄: | ||
function mt.__newindex(t, k, v) | function mt.__newindex(t, k, v) | ||
if k ~= 'arg' then | if k ~= 'arg' then | ||
error(' | error(require('Module:TNT').format('I18n/No globals', 'err-write', tostring(k)), 2) | ||
end | end | ||
rawset(t, k, v) | rawset(t, k, v) | ||
end | end | ||
setmetatable(_G, mt) | setmetatable(_G, mt) |
2020년 4월 1일 (수) 15:12 판
이 모듈은 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)