الفرق بين المراجعتين ل"وحدة:No globals"

من موسوعة المزرعة
اذهب إلى التنقل اذهب إلى البحث
imported>Meno25
ط (حمى "وحدة:No globals": صفحة كثيرة الاستخدام ([تعديل=السماح للمستخدمين المحررين فقط] (غير محدد) [النقل=السماح للمستخدمين المحررين فقط] (غير محدد)))
 
(أنشأ الصفحة ب'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....')
 
(لا فرق)

المراجعة الحالية بتاريخ 01:35، 28 مارس 2021

الاستخدام[عدل]


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)