Add check for undefined variables. Find undefined variables. Fix undefined

variables.
This commit is contained in:
David Given 2016-08-05 00:01:55 +02:00
parent 5e84be70fd
commit b50dc4214a
3 changed files with 16 additions and 4 deletions

View file

@ -361,7 +361,8 @@ local function loadbuildfile(filename)
data, e = fp:read("*a") data, e = fp:read("*a")
fp:close() fp:close()
if not e then if not e then
local thisglobals = {_G = thisglobals} local thisglobals = {}
thisglobals._G = thisglobals
setmetatable(thisglobals, {__index = globals}) setmetatable(thisglobals, {__index = globals})
chunk, e = load(data, "@"..filename, "text", thisglobals) chunk, e = load(data, "@"..filename, "text", thisglobals)
end end
@ -787,6 +788,18 @@ setmetatable(globals,
vars.cflags = {} vars.cflags = {}
parente.vars = vars parente.vars = vars
setmetatable(_G,
{
__index = function(self, k)
local value = rawget(_G, k)
if not value then
error(string.format("access of undefined variable '%s'", k))
end
return value
end
}
)
do do
local emitter_type = install_make_emitter local emitter_type = install_make_emitter
parse_arguments( parse_arguments(

View file

@ -1,6 +1,6 @@
include("util/cmisc/build.lua") include("util/cmisc/build.lua")
local allocd_header = definerule(null, local allocd_header = definerule(nil,
{ {
srcs = { type="targets" } srcs = { type="targets" }
}, },

View file

@ -26,8 +26,7 @@ definerule("build_ncg",
srcs = { srcs = {
"mach/proto/ncg/*.c", "mach/proto/ncg/*.c",
"mach/"..e.arch.."/ncg/mach.h", "mach/"..e.arch.."/ncg/mach.h",
archlib, -- for .c file matching(filenamesof(tables), "%.c$")
tables, -- for .c file
}, },
deps = { deps = {
"h+emheaders", "h+emheaders",