clean up repl functionality

[?]
May 11, 2022, 8:12 PM
D2GCFTTT2RNUBFB243YTA4F2H5ZXFTFHBSKHLZ2CX4JSKRZFTUUQC

Dependencies

Change contents

  • file addition: repl.lua (----------)
    [10.2]
    -- beginnings of a repl
    function eval(buf)
    local f = load('return '..buf, 'REPL')
    if f then
    return run(f)
    end
    local f, err = load(buf, 'REPL')
    if f then
    return run(f)
    else
    return {err}
    end
    end
    -- you could perform parse and run separately
    -- usually because there's a side-effect like drawing that you want to control the timing of
    function parse_into_exec_payload(buf)
    local f = load('return '..buf, 'REPL')
    if f then
    exec_payload = f
    return
    end
    local f, err = load(buf, 'REPL')
    if f then
    exec_payload = f
    return
    else
    return {err}
    end
    end
    -- based on https://github.com/hoelzro/lua-repl
    function run(f)
    local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))
    return results
    end
    function gather_results(success, ...)
    local n = select('#', ...)
    return success, { n = n, ... }
    end
  • edit in main.lua at line 3
    [2.19]
    [3.2]
    require 'repl'
  • edit in main.lua at line 70
    [3.23]
    [3.23]
    -- display side effect
  • replacement in main.lua at line 72
    [3.46][3.46:76]()
    call_gather(exec_payload)
    [3.46]
    [3.76]
    run(exec_payload)
  • replacement in main.lua at line 122
    [3.254][3.83:185]()
    eval(lines[#lines])
    --? lines[#lines+1] = eval(lines[#lines])[1]
    --? lines[#lines+1] = ''
    [3.254]
    [3.601]
    lines[#lines+1] = eval(lines[#lines])[1]
    lines[#lines+1] = ''
    elseif chord == 'C-d' then
    parse_into_exec_payload(lines[#lines])
  • edit in main.lua at line 135
    [3.464][3.464:465](),[3.465][3.176:248](),[3.612][3.176:248](),[3.248][3.186:248](),[3.248][3.274:327](),[3.274][3.274:327](),[3.327][3.249:311](),[3.311][3.353:679](),[3.353][3.353:679](),[3.653][3.653:657]()
    function eval(buf)
    local f = load('return '..buf, 'REPL')
    if f then
    exec_payload = f
    return
    --? return call_gather(f)
    end
    local f, err = load(buf, 'REPL')
    if f then
    exec_payload = f
    return
    --? return call_gather(f)
    else
    return {err}
    end
    end
    -- based on https://github.com/hoelzro/lua-repl
    function call_gather(f)
    local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))
    return results
    end
    function gather_results(success, ...)
    local n = select('#', ...)
    return success, { n = n, ... }
    end