<commit_before>local instanceName, configdir, path, cpath = ...

if _instance then

    print = function(...) _instance:print(...) end

    os.exit = function(...) _instance:cancel(...) end

    debug.sethook(function(t,l)
        if (_instance:isCancelled()) then
            error("** thread cancelled")
        end
    end, "", 1000)

    _sharedTable = {}
    setmetatable(_sharedTable, {
        __index    = function(t, k) return _instance:get(k) end,
        __newindex = function(t, k, v) _instance:set(k, v) end,
        __pairs    = function(t)
            local keys, values = _instance:keys(), {}
            for k, v in ipairs(keys) do values[v] = _instance:get(v) end
            return function(t, i)
                i = table.remove(keys, 1)
                if i then
                    return i, values[i]
                else
                    return nil
                end
            end, _sharedTable, nil
        end,
        __len      = function(t)
            local len, pos = 0, 1
            while _instance:get(pos) do
                len = pos
                pos = pos + 1
            end
            return len
        end,
        __metatable = "shared data:".._instance:name()
    })

    package.path  = path
    package.cpath = cpath

    hs            = {}
    hs.printf     = function(fmt,...) return print(string.format(fmt,...)) end
    hs.configdir  = configdir
    hs._exit      = os.exit
    hs.execute = function(command, user_env)
        local f
        if user_env then
          f = io.popen(os.getenv("SHELL")..[[ -l -i -c "]]..command..[["]], 'r')
        else
          f = io.popen(command, 'r')
        end
        local s = f:read('*a')
        local status, exit_type, rc = f:close()
        return s, status, exit_type, rc
    end

    hs.inspect    = require("hs.inspect")

    local runstring = function(s)
        --print("runstring")
        local fn, err = load("return " .. s)
        if not fn then fn, err = load(s) end
        if not fn then return tostring(err) end

        local str = ""
        local startTime = _instance:timestamp()
        local results = table.pack(xpcall(fn,debug.traceback))
        local endTime   = _instance:timestamp()

        local sharedResults = {}
        for i = 2,results.n do
            if i > 2 then str = str .. "\t" end
            str = str .. tostring(results[i])
            sharedResults[i - 1] = results[i]
        end
        _sharedTable._results = { start = startTime, stop = endTime, results = sharedResults }
        return str
    end

    print("-- ".._VERSION..", Hammerspoon instance "..instanceName)

    local custominit = configdir.."/_init."..instanceName..".lua"<commit_msg>minor tweak to results copy in shared dictionary<commit_after>local instanceName, configdir, path, cpath = ...

if _instance then

    print = function(...) _instance:print(...) end

    os.exit = function(...) _instance:cancel(...) end

    debug.sethook(function(t,l)
        if (_instance:isCancelled()) then
            error("** thread cancelled")
        end
    end, "", 1000)

    _sharedTable = {}
    setmetatable(_sharedTable, {
        __index    = function(t, k) return _instance:get(k) end,
        __newindex = function(t, k, v) _instance:set(k, v) end,
        __pairs    = function(t)
            local keys, values = _instance:keys(), {}
            for k, v in ipairs(keys) do values[v] = _instance:get(v) end
            return function(t, i)
                i = table.remove(keys, 1)
                if i then
                    return i, values[i]
                else
                    return nil
                end
            end, _sharedTable, nil
        end,
        __len      = function(t)
            local len, pos = 0, 1
            while _instance:get(pos) do
                len = pos
                pos = pos + 1
            end
            return len
        end,
        __metatable = "shared data:".._instance:name()
    })

    package.path  = path
    package.cpath = cpath

    hs            = {}
    hs.printf     = function(fmt,...) return print(string.format(fmt,...)) end
    hs.configdir  = configdir
    hs._exit      = os.exit
    hs.execute = function(command, user_env)
        local f
        if user_env then
          f = io.popen(os.getenv("SHELL")..[[ -l -i -c "]]..command..[["]], 'r')
        else
          f = io.popen(command, 'r')
        end
        local s = f:read('*a')
        local status, exit_type, rc = f:close()
        return s, status, exit_type, rc
    end

    hs.inspect    = require("hs.inspect")

    local runstring = function(s)
        --print("runstring")
        local fn, err = load("return " .. s)
        if not fn then fn, err = load(s) end
        if not fn then return tostring(err) end

        local str = ""
        local startTime = _instance:timestamp()
        local results = table.pack(xpcall(fn,debug.traceback))
        local endTime   = _instance:timestamp()

        local sharedResults = { n = results.n - 1 }
        for i = 2,results.n do
            if i > 2 then str = str .. "\t" end
            str = str .. tostring(results[i])
            sharedResults[i - 1] = results[i]
        end
        _sharedTable._results = { start = startTime, stop = endTime, results = sharedResults }
        return str
    end

    print("-- ".._VERSION..", Hammerspoon instance "..instanceName)

    local custominit = configdir.."/_init."..instanceName..".lua"
{'fraction_non_alphanumeric': 0.12467960454046137, 'fraction_numerical': 0.004210911753936287, 'mean_word_length': 1.6442400774443369, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6050735', 'n_tokens_mistral': 1679, 'n_tokens_neox': 1599, 'n_words': 453}