Files
itgmania212121/stepmania/src/lua-5.1/etc/strict.lua
T
Glenn Maynard 4564b0d5a2 Update to Lua 5.1.
This is normally statically linked in releases.  Lua also needs
some patching in Linux x86 to fix performance issues related
to alignment, will need patching if we want fine-grained threading,
and generally has an odd "build it yourself" design, so let's
just add embed this one.  (note: disable PCH for these files
in VC, and don't add lua.c, luac.c, or print.c to the project)
2006-09-25 07:35:34 +00:00

35 lines
806 B
Lua

--
-- strict.lua
-- checks uses of undeclared global variables
-- All global variables must be 'declared' through a regular assignment
-- (even assigning nil will do) in a main chunk before being used
-- anywhere or assigned to inside a function.
--
local mt = getmetatable(_G)
if mt == nil then
mt = {}
setmetatable(_G, mt)
end
mt.__declared = {}
mt.__newindex = function (t, n, v)
if not mt.__declared[n] then
local w = debug.getinfo(2, "S").what
if w ~= "main" and w ~= "C" then
error("assign to undeclared variable '"..n.."'", 2)
end
mt.__declared[n] = true
end
rawset(t, n, v)
end
mt.__index = function (t, n)
if not mt.__declared[n] and debug.getinfo(2, "S").what ~= "C" then
error("variable '"..n.."' is not declared", 2)
end
return rawget(t, n)
end