diff options
author | Volker Lendecke <vl@samba.org> | 2008-09-19 08:01:23 +0200 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2008-12-17 12:57:18 +0100 |
commit | 390f19b649b85a8f8ab762c6a4e9d1a3d23d3f47 (patch) | |
tree | 9f9506e36222640d23b086d62b32de940c526a98 /source3/lua-5.1.4/etc/strict.lua | |
parent | 081f8883bafc11ca7c08f868ec19f1ea32071837 (diff) | |
download | samba-390f19b649b85a8f8ab762c6a4e9d1a3d23d3f47.tar.gz samba-390f19b649b85a8f8ab762c6a4e9d1a3d23d3f47.tar.bz2 samba-390f19b649b85a8f8ab762c6a4e9d1a3d23d3f47.zip |
Add the Lua distibution from http://www.lua.org/ftp/lua-5.1.4.tar.gz
Available under the MIT license.
Adding it to see how the build farm likes it. They claim to be 100% pure
ANSI C and compile everywhere. Lets see. If it breaks badly, we can remove
it again.
Diffstat (limited to 'source3/lua-5.1.4/etc/strict.lua')
-rw-r--r-- | source3/lua-5.1.4/etc/strict.lua | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/source3/lua-5.1.4/etc/strict.lua b/source3/lua-5.1.4/etc/strict.lua new file mode 100644 index 0000000000..3ec2ab2ae5 --- /dev/null +++ b/source3/lua-5.1.4/etc/strict.lua @@ -0,0 +1,40 @@ +-- +-- 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 getinfo, error, rawset, rawget = debug.getinfo, error, rawset, rawget + +local mt = getmetatable(_G) +if mt == nil then + mt = {} + setmetatable(_G, mt) +end + +mt.__declared = {} + +local function what () + local d = getinfo(3, "S") + return d and d.what or "C" +end + +mt.__newindex = function (t, n, v) + if not mt.__declared[n] then + local w = 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 what() ~= "C" then + error("variable '"..n.."' is not declared", 2) + end + return rawget(t, n) +end |