Module:No globals : Différence entre versions

De Wiklou, le Wiki du Biclou
Aller à : navigation, rechercher
m (1 révision importée)
 
Ligne 2 : Ligne 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( "utilisation d'une variable globale, " .. tostring(k), 2 )
 
end
 
end
 
return nil
 
return nil
Ligne 8 : Ligne 8 :
 
function mt.__newindex(t, k, v)
 
function mt.__newindex(t, k, v)
 
if k ~= 'arg' then
 
if k ~= 'arg' then
error('Tried to write global ' .. tostring(k), 2)
+
error( "utilisation d'une variable globale, " .. tostring(k), 2 )
 
end
 
end
 
rawset(t, k, v)
 
rawset(t, k, v)
 
end
 
end
 
setmetatable(_G, mt)
 
setmetatable(_G, mt)

Version actuelle datée du 30 novembre 2017 à 23:19

La documentation pour ce module peut être créée à Module:No globals/doc

local mt = getmetatable(_G) or {}
function mt.__index (t, k)
	if k ~= 'arg' then
		error( "utilisation d'une variable globale, " .. tostring(k), 2 )
	end
	return nil
end
function mt.__newindex(t, k, v)
	if k ~= 'arg' then
		error( "utilisation d'une variable globale, " .. tostring(k), 2 )
	end
	rawset(t, k, v)
end
setmetatable(_G, mt)