imported>MusikAnimal m 1 revision imported |
imported>MusikAnimal Undid revision 948472525 by [[Special:Contributions/w>DiBabelYurikBot|w>DiBabelYurikBot]] ([[User talk:w>DiBabelYurikBot|talk]]) |
||
| 2번째 줄: | 2번째 줄: | ||
function mt.__index (t, k) | function mt.__index (t, k) | ||
if k ~= 'arg' then | if k ~= 'arg' then | ||
error('Tried to read nil global ' .. tostring(k), 2) | |||
error | |||
end | end | ||
return nil | return nil | ||
| 9번째 줄: | 8번째 줄: | ||
function mt.__newindex(t, k, v) | function mt.__newindex(t, k, v) | ||
if k ~= 'arg' then | if k ~= 'arg' then | ||
error | error('Tried to write global ' .. 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:28 판
이 모듈은 nil 전역 변수를 읽거나 전역 변수 기록을 할 경우(arg 제외) 오류를 발생시킵니다. 모듈 최상단에 require('Module:No globals')를 추가하여 이 모듈을 사용할 수 있습니다. arg 변수가 제외되는 이유는 Scribunto의 require 함수가 정상 동작해야 하기 때문에 그렇습니다. (Scribunto 소스 코드는 여기를 참고)
local mt = getmetatable(_G) or {}
function mt.__index (t, k)
if k ~= 'arg' then
error('Tried to read nil global ' .. tostring(k), 2)
end
return nil
end
function mt.__newindex(t, k, v)
if k ~= 'arg' then
error('Tried to write global ' .. tostring(k), 2)
end
rawset(t, k, v)
end
setmetatable(_G, mt)