This commit is contained in:
Kartik K. Agaram 2021-11-26 21:56:22 -08:00
parent 662d1cf202
commit 31816db0cc
4 changed files with 102 additions and 51 deletions

View File

@ -1,6 +1,7 @@
teliva_program = {
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
window = [==[
window = curses.stdscr()
-- animation-based app
@ -8,12 +9,14 @@ window:nodelay(true)
lines, cols = window:getmaxyx()]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
current_game = [==[
current_game = {}]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
piece_glyph = [==[
piece_glyph = {
-- for legibility, white pieces also use unicode glyphs for black pieces
@ -33,7 +36,8 @@ piece_glyph = {
}]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
top_player = [==[
function top_player(current_game)
if current_game.players[1].color == "black" then
@ -43,7 +47,8 @@ function top_player(current_game)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
bottom_player = [==[
function bottom_player(current_game)
if current_game.players[1].color == "white" then
@ -53,7 +58,8 @@ function bottom_player(current_game)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render_player = [==[
function render_player(y, x, player)
curses.mvaddstr(y, x, player.user.name)
@ -62,7 +68,8 @@ function render_player(y, x, player)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render_square = [==[
function render_square(current_game, rank, file, highlighted_squares)
-- decide whether to highlight
@ -85,7 +92,8 @@ function render_square(current_game, rank, file, highlighted_squares)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render_fen_rank = [==[
function render_fen_rank(rank, fen_rank, highlighted_squares)
local file = 1
@ -124,7 +132,8 @@ function render_fen_rank(rank, fen_rank, highlighted_squares)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render_time = [==[
function render_time(y, x, seconds)
if seconds == nil then return end
@ -133,7 +142,8 @@ function render_time(y, x, seconds)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render_board = [==[
function render_board(current_game)
--? curses.mvaddstr(1, 50, dump(current_game.fen))
@ -151,7 +161,8 @@ function render_board(current_game)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
parse_lm = [==[
function parse_lm(move)
--? curses.mvaddstr(4, 50, move)
@ -164,7 +175,8 @@ function parse_lm(move)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render = [==[
function render(chunk)
local o = json.decode(chunk)
@ -187,7 +199,8 @@ function render(chunk)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
init_colors = [==[
function init_colors()
-- colors
@ -209,7 +222,8 @@ function init_colors()
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
main = [==[
function main()
init_colors()
@ -228,7 +242,8 @@ function main()
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
utf8 = [==[
-- https://stackoverflow.com/questions/7983574/how-to-write-a-unicode-symbol-in-lua
function utf8(decimal)
@ -250,7 +265,8 @@ function utf8(decimal)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
split = [==[
function split(s, pat)
result = {}
@ -261,7 +277,8 @@ function split(s, pat)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
dump = [==[
-- https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console
function dump(o)

View File

@ -1,16 +1,19 @@
teliva_program = {
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
window = [==[
window = curses.stdscr()]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
n = [==[
n = 0]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render = [==[
function render(window)
window:clear()
@ -24,12 +27,14 @@ function render(window)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
menu = [==[
menu = {Enter="increment"}]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
update = [==[
function update(window)
local key = curses.getch()
@ -39,7 +44,8 @@ function update(window)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
main = [==[
function main()
for i=1,7 do

View File

@ -1,6 +1,7 @@
teliva_program = {
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render = [==[
function render(window)
window:clear()
@ -14,7 +15,8 @@ function render(window)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
lines = [==[
function lines(window)
local lines, cols = window:getmaxyx()
@ -22,19 +24,22 @@ function lines(window)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
pop = [==[
function pop(array)
return table.remove(array)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
window = [==[
window = curses.stdscr()]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render_tower = [==[
function render_tower(window, line, col, tower_index, tower)
window:attron(curses.A_BOLD)
@ -56,12 +61,14 @@ function render_tower(window, line, col, tower_index, tower)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
tower = [==[
tower = {{6, 5, 4, 3, 2}, {}, {}}]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render_disk = [==[
function render_disk(window, line, col, size)
col = col-size+1
@ -74,7 +81,8 @@ function render_disk(window, line, col, size)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
main = [==[
function main()
for i=1,7 do
@ -89,7 +97,8 @@ end
]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
len = [==[
function len(array)
local result = 0
@ -100,7 +109,8 @@ function len(array)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
update = [==[
function update(window)
window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ")
@ -111,7 +121,8 @@ function update(window)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
make_move = [==[
function make_move(from, to)
local disk = pop(tower[from])
@ -119,7 +130,8 @@ function make_move(from, to)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
cols = [==[
function cols(window)
local lines, cols = window:getmaxyx()

View File

@ -1,6 +1,7 @@
teliva_program = {
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
grid = [==[
-- main data structure
grid = {}
@ -13,7 +14,8 @@ end
]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
window = [==[
window = curses.stdscr()
-- animation-based app
@ -21,7 +23,8 @@ window:nodelay(true)
lines, cols = window:getmaxyx()]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
grid_char = [==[
-- grab a 4x2 chunk of grid
function grid_char(line, col)
@ -33,7 +36,8 @@ function grid_char(line, col)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
print_grid_char = [==[
function print_grid_char(window, x)
result = {}
@ -46,7 +50,8 @@ function print_grid_char(window, x)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
glyph = [==[
-- look up the braille pattern corresponding to a 4x2 chunk of grid
-- https://en.wikipedia.org/wiki/Braille_Patterns
@ -72,7 +77,8 @@ glyph = {
}]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
utf8 = [==[
-- https://stackoverflow.com/questions/7983574/how-to-write-a-unicode-symbol-in-lua
function utf8(decimal)
@ -94,7 +100,8 @@ function utf8(decimal)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
grid_char_to_glyph_index = [==[
-- convert a chunk of grid into a number
function grid_char_to_glyph_index(g)
@ -104,7 +111,8 @@ function grid_char_to_glyph_index(g)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
render = [==[
function render(window)
window:clear()
@ -118,7 +126,8 @@ end
]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
state = [==[
function state(line, col)
if line < 1 or line > table.getn(grid) or col < 1 or col > table.getn(grid[1]) then
@ -128,7 +137,8 @@ function state(line, col)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
num_live_neighbors = [==[
function num_live_neighbors(line, col)
return state(line-1, col-1) + state(line-1, col) + state(line-1, col+1) +
@ -137,7 +147,8 @@ function num_live_neighbors(line, col)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
step = [==[
function step()
local new_grid = {}
@ -158,7 +169,8 @@ function step()
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
sleep = [==[
function sleep(a)
local sec = tonumber(os.clock() + a);
@ -167,7 +179,8 @@ function sleep(a)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
file_exists = [==[
function file_exists(filename)
local f = io.open(filename, "r")
@ -180,7 +193,8 @@ function file_exists(filename)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
load_file = [==[
function load_file(window, filename)
io.input(filename)
@ -203,7 +217,8 @@ function load_file(window, filename)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
update = [==[
menu = {arrow="pan"}
@ -244,7 +259,8 @@ function update(window, c)
end]==],
},
{
__teliva_timestamp = [==[original]==],
__teliva_timestamp = [==[
original]==],
main = [==[
function main()
for i=1,7 do