prevent overriding foundational definitions

[?]
Apr 10, 2023, 5:17 AM
UUX7J2OA544YWISPG3A6FJ6GKAS2MLESZZMCZN7KVCKMDVYJDZGQC

Dependencies

Change contents

  • edit in main.lua at line 39
    [4.1269]
    [4.1269]
    app.freeze_all_existing_definitions()
  • edit in main.lua at line 51
    [2.45]
    [4.1492]
    end
    -- Everything that exists before we start loading the live files is frozen and
    -- can't be edited live.
    function app.freeze_all_existing_definitions()
    app.Frozen_definitions = {on=true} -- special case for version 1
    local done = {}
    done[app.Frozen_definitions]=true
    app.freeze_all_existing_definitions_in(_G, {}, done)
    end
    function app.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 = app.full_name(scopes, name)
    --? print(full_name)
    app.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)
    app.freeze_all_existing_definitions_in(binding, scopes, done)
    table.remove(scopes)
    end
    end
    end
    function app.full_name(scopes, name)
    local ns = table.concat(scopes, '.')
    if #ns == 0 then return name end
    return ns..'.'..name
  • edit in main.lua at line 294
    [4.6748]
    [4.6748]
    if app.Frozen_definitions[binding] then
    app.send('ERROR definition '..binding..' is part of Freewheeling infrastructure and cannot be safely edited live.')
    return
    end