clean up repl functionality
[?]
May 11, 2022, 8:12 PM
D2GCFTTT2RNUBFB243YTA4F2H5ZXFTFHBSKHLZ2CX4JSKRZFTUUQCDependencies
- [2]
XX7G2FFJintermingle freehand line drawings with text - [3]
OTIBCAUJlove2d scaffold - [4]
6LJZN727handle chords - [5]
6Q6XGOFLlittle Lua repl on hitting ctrl-r - [6]
IZZVOCLBconfirm that we have access to all of the love API - [7]
QU7NHFOVshow cursor - [8]
6PUNJS5Bbackspace - [*]
R5QXEHUIsomebody stop me
Change contents
- file addition: repl.lua[10.2]
-- beginnings of a replfunction eval(buf)local f = load('return '..buf, 'REPL')if f thenreturn run(f)endlocal f, err = load(buf, 'REPL')if f thenreturn run(f)elsereturn {err}endend-- you could perform parse and run separately-- usually because there's a side-effect like drawing that you want to control the timing offunction parse_into_exec_payload(buf)local f = load('return '..buf, 'REPL')if f thenexec_payload = freturnendlocal f, err = load(buf, 'REPL')if f thenexec_payload = freturnelsereturn {err}endend-- based on https://github.com/hoelzro/lua-replfunction run(f)local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))return resultsendfunction gather_results(success, ...)local n = select('#', ...)return success, { n = n, ... }end - edit in main.lua at line 3
require 'repl' - edit in main.lua at line 70
-- display side effect - replacement in main.lua at line 72
call_gather(exec_payload)run(exec_payload) - replacement in main.lua at line 122
eval(lines[#lines])--? lines[#lines+1] = eval(lines[#lines])[1]--? lines[#lines+1] = ''lines[#lines+1] = eval(lines[#lines])[1]lines[#lines+1] = ''elseif chord == 'C-d' thenparse_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 thenexec_payload = freturn--? return call_gather(f)endlocal f, err = load(buf, 'REPL')if f thenexec_payload = freturn--? return call_gather(f)elsereturn {err}endend-- based on https://github.com/hoelzro/lua-replfunction call_gather(f)local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))return resultsendfunction gather_results(success, ...)local n = select('#', ...)return success, { n = n, ... }end