lua-users home
lua-l archive

Re: [5.1.4/newbie] "attempt to index ... 'file' (a nil value)"?

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


-- slight typo don't forget table parameter in index..
do
 local mt = getmetatable(_G) or {}
 mt.__index = function(t,k) error("Global "..k.." does not exist", 2) end
 setmetatable(_G, mt)
end
n1="string"
print(n1) -- prints string
local n2 print(n2) -- prints nil
print(n3) -- prints Global n3 does not exists
On Fri, Feb 18, 2011 at 8:59 AM, Luiz Henrique de Figueiredo
<lhf@tecgraf.puc-rio.br> wrote:
>> Best is to add a metatable to globals _G that errors on index.
>
> See also etc/strict.lua which does this and more.
>
>

AltStyle によって変換されたページ (->オリジナル) /