« Module:No globals » : différence entre les versions

De Wiklou, le Wiki du Biclou
Aller à la navigation Aller à la recherche
m 1 révision importée
 
Velomobile (discussion | contributions)
Aucun résumé des modifications
 
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)

Dernière version du 30 novembre 2017 à 21: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)