This commit is contained in:
Kartik K. Agaram 2023-04-15 10:14:42 -07:00
parent b6cb27ddf2
commit 6274322412

View File

@ -42,37 +42,6 @@ function live.initialize(arg)
if on.load then on.load() end
end
-- Everything that exists before we start loading the live files is frozen and
-- can't be edited live.
function live.freeze_all_existing_definitions()
Live.frozen_definitions = {on=true} -- special case for version 1
local done = {}
done[Live.frozen_definitions]=true
live.freeze_all_existing_definitions_in(_G, {}, done)
end
function live.freeze_all_existing_definitions_in(tab, scopes, done)
-- track duplicates to avoid cycles like _G._G, _G._G._G, etc.
if done[tab] then return end
done[tab] = true
for name,binding in pairs(tab) do
local full_name = live.full_name(scopes, name)
--? print(full_name)
Live.frozen_definitions[full_name] = true
if type(binding) == 'table' and full_name ~= 'package' then -- var 'package' contains copies of all modules, but not the best name; rely on people to not modify package.loaded.io.open, etc.
table.insert(scopes, name)
live.freeze_all_existing_definitions_in(binding, scopes, done)
table.remove(scopes)
end
end
end
function live.full_name(scopes, name)
local ns = table.concat(scopes, '.')
if #ns == 0 then return name end
return ns..'.'..name
end
function live.load_files_so_far()
print('new edits will go to ' .. love.filesystem.getSaveDirectory())
local files = {}
@ -361,7 +330,41 @@ function live.eval(buf)
end
end
-- ========= on error, pause the app and wait for messages
-- === infrastructure for performing various safety checks on any new definition
-- Everything that exists before we start loading the live files is frozen and
-- can't be edited live.
function live.freeze_all_existing_definitions()
Live.frozen_definitions = {on=true} -- special case for version 1
local done = {}
done[Live.frozen_definitions]=true
live.freeze_all_existing_definitions_in(_G, {}, done)
end
function live.freeze_all_existing_definitions_in(tab, scopes, done)
-- track duplicates to avoid cycles like _G._G, _G._G._G, etc.
if done[tab] then return end
done[tab] = true
for name,binding in pairs(tab) do
local full_name = live.full_name(scopes, name)
--? print(full_name)
Live.frozen_definitions[full_name] = true
if type(binding) == 'table' and full_name ~= 'package' then -- var 'package' contains copies of all modules, but not the best name; rely on people to not modify package.loaded.io.open, etc.
table.insert(scopes, name)
live.freeze_all_existing_definitions_in(binding, scopes, done)
table.remove(scopes)
end
end
end
function live.full_name(scopes, name)
local ns = table.concat(scopes, '.')
if #ns == 0 then return name end
return ns..'.'..name
end
-- === on error, pause the app and wait for messages
-- return nil to continue the event loop, non-nil to quit
function live.handle_error(err)