모듈:No globals: 두 판 사이의 차이

imported>Xaosflux
m (Changed protection level for "Module:No globals": Used in interface MediaWiki:Protectedpagetext ([Edit=Require administrator access] (indefinite) [Move=Require administrator access] (indefinite)))
m (1 revision imported from w:Module:No_globals: per RFH)
(차이 없음)

2019년 3월 23일 (토) 05:54 판

이 모듈은 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)
• 현재 페이지 URL 줄이기