diff options
Diffstat (limited to 'script/vm/globals.lua')
-rw-r--r-- | script/vm/globals.lua | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/script/vm/globals.lua b/script/vm/globals.lua index cf18aa19..7a0eeb59 100644 --- a/script/vm/globals.lua +++ b/script/vm/globals.lua @@ -2,24 +2,39 @@ local files = require 'files' local await = require 'await' local noder = require 'core.noder' -local globalsMap = {} -local subscribe = {} +local globalsMap = {} +local subscribeMap = {} local function popGlobals(uri) - + if not subscribeMap[uri] then + return + end + for id in pairs(subscribeMap[uri]) do + if globalsMap[id] then + globalsMap[id][uri] = nil + end + end + subscribeMap[uri] = nil end local function pushGlobals(uri) + subscribeMap[uri] = {} local state = files.getState(uri) if not state then return end - noder.compileNodes(state.ast) - + local nodes = noder.compileNodes(state.ast) + for id in pairs(nodes) do + if id:sub(1, 2) == 'g:' then + if not globalsMap[id] then + globalsMap[id] = {} + end + globalsMap[id][uri] = true + subscribeMap[uri][id] = true + end + end end -local m = {} - files.watch(function (ev, uri) if ev == 'update' then popGlobals(uri) @@ -28,4 +43,10 @@ files.watch(function (ev, uri) end end) +local m = {} + +function m.getUrisByID(id) + return globalsMap[id] +end + return m |