diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-14 00:49:40 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-14 00:52:25 -0800 |
commit | 5be743324c860f224ddd6d4bd1d3177b3422818c (patch) | |
tree | b68b2b781eaf626a6164a17472c85fe23bc8fb7f /hanoi.tlv | |
parent | b64a21771e06ae798e0fcdeebc662fc2f2159ed4 (diff) | |
download | teliva-5be743324c860f224ddd6d4bd1d3177b3422818c.tar.gz |
slightly more robust on-disk format
Looks like Lua supports a little bit of programmability in its multi-line string literals. Even though I can't find this documented anywhere.
Diffstat (limited to 'hanoi.tlv')
-rw-r--r-- | hanoi.tlv | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/hanoi.tlv b/hanoi.tlv index 7cec549..28efbdc 100644 --- a/hanoi.tlv +++ b/hanoi.tlv @@ -1,5 +1,5 @@ teliva_program = { - render = [[function render(window) + render = [==[function render(window) window:clear() local lines, cols = window:getmaxyx() local line = math.floor(lines/2) @@ -8,16 +8,16 @@ teliva_program = { render_tower(window, line, i*col, i, t) end curses.refresh() -end]], - lines = [[function lines(window) +end]==], + lines = [==[function lines(window) local lines, cols = window:getmaxyx() return lines -end]], - pop = [[function pop(array) +end]==], + pop = [==[function pop(array) return table.remove(array) -end]], - window = [[window = curses.stdscr()]], - render_tower = [[function render_tower(window, line, col, tower_index, tower) +end]==], + window = [==[window = curses.stdscr()]==], + render_tower = [==[function render_tower(window, line, col, tower_index, tower) window:attron(curses.A_BOLD) window:mvaddch(line+2, col, string.char(96+tower_index)) window:attroff(curses.A_BOLD) @@ -34,9 +34,9 @@ end]], window:attroff(curses.color_pair(7)) line = line - 1 end -end]], - tower = [[tower = {{6, 5, 4, 3, 2}, {}, {}}]], - render_disk = [[function render_disk(window, line, col, size) +end]==], + tower = [==[tower = {{6, 5, 4, 3, 2}, {}, {}}]==], + render_disk = [==[function render_disk(window, line, col, size) col = col-size+1 for i=1,size do window:attron(curses.color_pair(size)) @@ -44,8 +44,8 @@ end]], window:attroff(curses.color_pair(size)) col = col+2 end -end]], - main = [[function main() +end]==], + main = [==[function main() for i=1,7 do curses.init_pair(i, 0, i) end @@ -55,27 +55,27 @@ end]], update(window) end end -]], - len = [[function len(array) +]==], + len = [==[function len(array) local result = 0 for k in pairs(array) do result = result+1 end return result -end]], - update = [[function update(window) +end]==], + update = [==[function update(window) window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ") local from = curses.getch() - 96 window:mvaddstr(lines(window)-1, 5, "tower to stack it on? ") local to = curses.getch() - 96 make_move(from, to) -end]], - make_move = [[function make_move(from, to) +end]==], + make_move = [==[function make_move(from, to) local disk = pop(tower[from]) table.insert(tower[to], disk) -end]], - cols = [[function cols(window) +end]==], + cols = [==[function cols(window) local lines, cols = window:getmaxyx() return cols -end]], +end]==], } |