about summary refs log tree commit diff stats
path: root/archive/2.transect/compiler2
Commit message (Expand)AuthorAgeFilesLines
* 5852Kartik Agaram2020-01-011-0/+27
22:08:28 -0700 committer Kartik K. Agaram <vc@akkartik.com> 2022-04-25 22:08:28 -0700 repl' href='/akkartik/lines.love/commit/mu.lua?id=45508a440f91e893f863a0479d87109b58c74bd0'>45508a4 ^
45508a4 ^
















a200d71 ^














45508a4 ^








a200d71 ^
45508a4 ^


a200d71 ^
45508a4 ^
dfd67ae ^

45508a4 ^

a200d71 ^
dfd67ae ^
dfd67ae ^



a200d71 ^
dfd67ae ^


45508a4 ^



6762fac
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73


                               
                                                                                                
              

                     
















                                           














                                                                                                








                         
                                        


                   
                 
      

                                    

                     
                   
        



                                                                          
                                


                       



       
               
curses = require 'curses'

local stdscr = curses.initscr()
curses.echo(false) -- unclear why implicit echo can't handle newlines, regardless of stdscr:nl()
stdscr:clear()
stdscr:scrollok(true)

local function gather_results(success, ...)
  local n = select('#', ...)
  return success, { n = n, ... }
end

local function readline()
  local result = ''
  while true do
    local x = stdscr:getch()
    stdscr:addch(x)
    local c = string.char(x)
    result = result .. c
    if c == '\n' then break end
  end
  return result
end

function eval_print(f)
  local success, results = gather_results(xpcall(f, function(...) return debug.traceback() end))
  if success then
    for i, result in ipairs(results) do
      if i > 1 then
        stdscr:addch('\t')
      end
      stdscr:addstr(tostring(result))
    end
  else
    stdscr:addstr(tostring(result[1]))
  end
  stdscr:addch('\n')
end

local new_expr = true
local buf = ''
while true do
  if new_expr then
    stdscr:addstr('> ')
  else
    stdscr:addstr('>> ')
  end
  buf = buf .. readline()
  local f = load('return '..buf, 'REPL')
  if f then
    buf = ''
    new_expr = true
    eval_print(f)
  else
    local f, err = load(buf, 'REPL')
    if f then
      buf = ''
      new_expr = true
      eval_print(f)
    else
      if string.match(err, "'<eof>'$") or string.match(err, "<eof>$") then
        buf = buf .. '\n'
        new_expr = false
      else
        stdscr:addstr(err..'\n')
        buf = ''
        new_expr = true
      end
    end
  end
end

curses.endwin()