From 191ba416c8b611ea4901cead138789a357c56134 Mon Sep 17 00:00:00 2001 From: Alexander Pickering Date: Sun, 2 Apr 2017 20:05:56 -0400 Subject: I finally had some time to work on this... dependency added on bobbleheadbob's zone addon --- gamemode/nrequire.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'gamemode/nrequire.lua') diff --git a/gamemode/nrequire.lua b/gamemode/nrequire.lua index d437a5e..6595fed 100644 --- a/gamemode/nrequire.lua +++ b/gamemode/nrequire.lua @@ -106,7 +106,10 @@ local function scan(pretbl, name) assert(cursor ~= nil,string.format("Scan did not find a file named %q, valid files are:\n\t%s",filename,table.concat(collect_paths(pretbl),"\n\t"))) local rev = {} for i = 1, #pathparts do rev[#pathparts - i + 1] = pathparts[i] end - for k,v in ipairs(rev) do cursor = cursor[v] end + for k,v in ipairs(rev) do + if cursor == nil then error(string.format("Scan could not complete file path translation while translateing %q at %s",table.concat(rev,","),v)) end + cursor = cursor[v] + end while type(cursor) ~= "string" do assert(type(cursor) ~= "nil",string.format("Could not find a valid file for path %q, file paths:\n\t%s",name,table.concat(collect_paths(pretbl),"\n\t"))) assert(tbllen(cursor) == 1,string.format("Ambiguous scan, there are two or more paths that match %q\n\t%s\nSpecify more of the file path.",name,table.concat(collect_paths(cursor),"\n\t"))) @@ -136,7 +139,7 @@ local pathstack = {} function nrequire(req) local tpath = scan(ntbl,req) if reqtbl[tpath] then - print("Cache hit! returning",reqtbl[tpath]) + --print("Cache hit! returning",reqtbl[tpath]) --for k,v in pairs(reqtbl[tpath]) do print(k,":",v) end return reqtbl[tpath] end @@ -146,9 +149,12 @@ function nrequire(req) local tab_rep = {} for k = 1, #pathstack do tab_rep[k] = "\t" end print(string.format("%sIncluding %q",table.concat(tab_rep),tpath)) + local oldprint = print + print = function(...) oldprint(" ",unpack({...})) end pathstack[#pathstack + 1] = tpath reqtbl[tpath] = include(tpath) pathstack[#pathstack] = nil + print = oldprint print(string.format("%sIncluded %q",table.concat(tab_rep),tpath)) return reqtbl[tpath] end -- cgit v1.2.3-70-g09d2