1-- 2-- Copyright (C) 2015 - Garrett Regier 3-- 4-- libpeas is free software; you can redistribute it and/or 5-- modify it under the terms of the GNU Lesser General Public 6-- License as published by the Free Software Foundation; either 7-- version 2.1 of the License, or (at your option) any later version. 8-- 9-- libpeas is distributed in the hope that it will be useful, 10-- but WITHOUT ANY WARRANTY; without even the implied warranty of 11-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12-- Lesser General Public License for more details. 13-- 14-- You should have received a copy of the GNU Lesser General Public 15-- License along with this library; if not, write to the Free Software 16-- Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17-- 18-- Modified version of: http://metalua.luaforge.net/src/lib/strict.lua.html 19 20__STRICT = true 21 22local mt = getmetatable(_G) 23if mt == nil then 24 mt = {} 25 setmetatable(_G, mt) 26end 27 28function mt:__newindex(name, value) 29 if __STRICT then 30 local what = debug.getinfo(2, 'S').what 31 32 if what ~= 'C' then 33 error("Attempted to create global variable '" .. 34 tostring(name) .. "'", 2) 35 end 36 end 37 38 rawset(self, name, value) 39end 40 41function mt:__index(name) 42 if not __STRICT or debug.getinfo(2, 'S').what == 'C' then 43 return rawget(self, name) 44 end 45 46 error("Attempted to access nonexistent " .. 47 "global variable '" .. tostring(name) .. "'", 2) 48end 49 50-- ex:ts=4:et: 51