We're going to focus on a simple text editor for now.
VXORMHME4X64HL6AC7BVYMSYEAYASG6RENGUZ7PEIZ4YQJ7ZHBIQC
FBDRL6LHPTBPMU3R356OLY4XE4ELQQEDXMCZGCBT2RFHLR7VQXQAC
R5QXEHUIZLELJGGCZAE7ATNS3CLRJ7JFRENMGH4XXH24C5WABZDQC
D2GCFTTT2RNUBFB243YTA4F2H5ZXFTFHBSKHLZ2CX4JSKRZFTUUQC
XX7G2FFJ4QCGQGD4REAW5QFHVYAKCFUPGZCK7L6DFGS5ISVBYBQQC
OTIBCAUJ3KDQJLVDN3A536DLZGNRYMGJLORZVR3WLCGXGO6UGO6AC
JVRL5TWLBTWMTHJDZSDN5XQDMEIIPVAZBKUP75HMO7JHURAYWG5QC
2C7CTIQYDDYVQJNKX2OSHZ6VMAMPOGNUVTSFAUV7HQCPMZR2YRUAC
IZZVOCLB7KB4ZNQ35OL466MHWOK3XZMOS7ZPFLHUFQ47LJLQQQ3QC
QU7NHFOVGFSKQ3CWG7EF2Q7GKP3Z6FHGTIDXFHHMSFL6XMUOHMEAC
6PUNJS5BSLTYMYMN4JFD7YDEGVQLM5PGAT7PQIG5NIAKLTM5T4PQC
6LJZN727CRPYR34LV75CQF55YZI3E7MGESYZSFSYAE73SNEZE3FAC
-- 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
elseif chord == 'C-r' then
lines[#lines+1] = eval(lines[#lines])[1]
lines[#lines+1] = ''
elseif chord == 'C-x' then
parse_into_exec_payload(lines[#lines])