delete experimental REPL
We're going to focus on a simple text editor for now.
This commit is contained in:
parent
21a4d8a67e
commit
551985e383
13
main.lua
13
main.lua
|
@ -1,6 +1,5 @@
|
||||||
require 'keychord'
|
require 'keychord'
|
||||||
require 'button'
|
require 'button'
|
||||||
require 'repl'
|
|
||||||
local utf8 = require 'utf8'
|
local utf8 = require 'utf8'
|
||||||
|
|
||||||
-- lines is an array of lines
|
-- lines is an array of lines
|
||||||
|
@ -46,8 +45,6 @@ function coord(n) -- pixels to parts
|
||||||
return math.floor(n*256/drawingw)
|
return math.floor(n*256/drawingw)
|
||||||
end
|
end
|
||||||
|
|
||||||
exec_payload = nil
|
|
||||||
|
|
||||||
filename = nil
|
filename = nil
|
||||||
|
|
||||||
function love.load(arg)
|
function love.load(arg)
|
||||||
|
@ -155,11 +152,6 @@ function love.draw()
|
||||||
-- cursor
|
-- cursor
|
||||||
love.graphics.setColor(0,0,0)
|
love.graphics.setColor(0,0,0)
|
||||||
love.graphics.print('_', 25+text:getWidth()*1.5, y)
|
love.graphics.print('_', 25+text:getWidth()*1.5, y)
|
||||||
|
|
||||||
-- display side effect
|
|
||||||
if exec_payload then
|
|
||||||
run(exec_payload)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
|
@ -512,11 +504,6 @@ function keychord_pressed(chord)
|
||||||
lines[#lines] = string.sub(lines[#lines], 1, byteoffset-1)
|
lines[#lines] = string.sub(lines[#lines], 1, byteoffset-1)
|
||||||
end
|
end
|
||||||
end
|
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])
|
|
||||||
elseif chord == 'escape' and love.mouse.isDown('1') then
|
elseif chord == 'escape' and love.mouse.isDown('1') then
|
||||||
local drawing = current_drawing()
|
local drawing = current_drawing()
|
||||||
drawing.pending = {}
|
drawing.pending = {}
|
||||||
|
|
42
repl.lua
42
repl.lua
|
@ -1,42 +0,0 @@
|
||||||
-- 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
|
|
Loading…
Reference in New Issue
Block a user