From: David Given Date: Thu, 4 Aug 2016 22:01:55 +0000 (+0200) Subject: Add check for undefined variables. Find undefined variables. Fix undefined X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=b50dc4214a477f106a20fd04d417c7d7488603fe;p=ack.git Add check for undefined variables. Find undefined variables. Fix undefined variables. --- diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index 1a150cb4a..0f83c4936 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -361,7 +361,8 @@ local function loadbuildfile(filename) data, e = fp:read("*a") fp:close() if not e then - local thisglobals = {_G = thisglobals} + local thisglobals = {} + thisglobals._G = thisglobals setmetatable(thisglobals, {__index = globals}) chunk, e = load(data, "@"..filename, "text", thisglobals) end @@ -787,6 +788,18 @@ setmetatable(globals, vars.cflags = {} 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 local emitter_type = install_make_emitter parse_arguments( diff --git a/lang/cem/cpp.ansi/build.lua b/lang/cem/cpp.ansi/build.lua index 0cc57fe9f..1f22fe88f 100644 --- a/lang/cem/cpp.ansi/build.lua +++ b/lang/cem/cpp.ansi/build.lua @@ -1,6 +1,6 @@ include("util/cmisc/build.lua") -local allocd_header = definerule(null, +local allocd_header = definerule(nil, { srcs = { type="targets" } }, diff --git a/mach/proto/ncg/build.lua b/mach/proto/ncg/build.lua index e093f891e..5245fd2a7 100644 --- a/mach/proto/ncg/build.lua +++ b/mach/proto/ncg/build.lua @@ -26,8 +26,7 @@ definerule("build_ncg", srcs = { "mach/proto/ncg/*.c", "mach/"..e.arch.."/ncg/mach.h", - archlib, -- for .c file - tables, -- for .c file + matching(filenamesof(tables), "%.c$") }, deps = { "h+emheaders",