Lompat ke isi

Modul:No globals: Perbedaan antara revisi

Dari Kupipedia
Mediawiki>MusikAnimal
Undid revision 948472525 by [[Special:Contributions/w>DiBabelYurikBot|w>DiBabelYurikBot]] ([[User talk:w>DiBabelYurikBot|talk]])
k 1 revisi diimpor
Baris 2: Baris 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('Argumen kosong ' .. tostring(k), 2)
end
end
return nil
return nil
Baris 8: Baris 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('Argumen kosong ' .. tostring(k), 2)
end
end
rawset(t, k, v)
rawset(t, k, v)
end
end
setmetatable(_G, mt)
setmetatable(_G, mt)

Revisi per 30 Juli 2021 04.48

Dokumentasi untuk modul ini dapat dibuat di Modul:No globals/doc

local mt = getmetatable(_G) or {}
function mt.__index (t, k)
	if k ~= 'arg' then
		error('Argumen kosong ' .. tostring(k), 2)
	end
	return nil
end
function mt.__newindex(t, k, v)
	if k ~= 'arg' then
		error('Argumen kosong ' .. tostring(k), 2)
	end
	rawset(t, k, v)
end
setmetatable(_G, mt)