Module:No globals: திருத்தங்களுக்கு இடையிலான வேறுபாடு
Jump to navigation
Jump to search
உள்ளடக்கம் நீக்கப்பட்டது உள்ளடக்கம் சேர்க்கப்பட்டது
←Created page with 'local mt = getmetatable(_G) or {} local oldIndex = mt.__index or function() return nil end mt.__index = function(t, k) if k ~= 'name' and k ~= 'arg' then erro...' |
don't bother saving old __index or __newindex |
||
| வரிசை 1: | வரிசை 1: | ||
local mt = getmetatable(_G) or {} |
local mt = getmetatable(_G) or {} |
||
function mt.__index (t, k) |
|||
mt.__index = function(t, k) |
|||
if k ~= 'name' and k ~= 'arg' then |
if k ~= 'name' and k ~= 'arg' then |
||
error('Tried to read nil global ' .. tostring(k), 2) |
error('Tried to read nil global ' .. tostring(k), 2) |
||
end |
end |
||
return |
return nil |
||
end |
end |
||
local oldNewindex = mt.__newindex or rawset |
|||
function mt.__newindex(t, k, v) |
function mt.__newindex(t, k, v) |
||
if k ~= 'name' and k ~= 'arg' then |
if k ~= 'name' and k ~= 'arg' then |
||
error('Tried to write global ' .. tostring(k), 2) |
error('Tried to write global ' .. tostring(k), 2) |
||
end |
end |
||
rawset(t, k, v) |
|||
end |
end |
||
setmetatable(_G, mt) |
setmetatable(_G, mt) |
||
20:46, 23 ஏப்பிரல் 2014 இல் நிலவும் திருத்தம்
| This Lua module is used on many pages and changes may be widely noticed. Test changes in the module's /sandbox or /testcases subpages, or in your own module sandbox. Consider discussing changes on the talk page before implementing them. |
வார்ப்புரு:Shared Template Warning
local mt = getmetatable(_G) or {}
function mt.__index (t, k)
if k ~= 'name' and k ~= 'arg' then
error('Tried to read nil global ' .. tostring(k), 2)
end
return nil
end
function mt.__newindex(t, k, v)
if k ~= 'name' and k ~= 'arg' then
error('Tried to write global ' .. tostring(k), 2)
end
rawset(t, k, v)
end
setmetatable(_G, mt)