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.
This commit is contained in:
parent
b64a21771e
commit
5be743324c
18
counter.tlv
18
counter.tlv
|
@ -1,7 +1,7 @@
|
||||||
teliva_program = {
|
teliva_program = {
|
||||||
window = [[window = curses.stdscr()]],
|
window = [==[window = curses.stdscr()]==],
|
||||||
n = [[n = 0]],
|
n = [==[n = 0]==],
|
||||||
render = [[
|
render = [==[
|
||||||
function render(window)
|
function render(window)
|
||||||
window:clear()
|
window:clear()
|
||||||
window:attron(curses.A_BOLD)
|
window:attron(curses.A_BOLD)
|
||||||
|
@ -12,17 +12,17 @@ function render(window)
|
||||||
window:attroff(curses.A_BOLD)
|
window:attroff(curses.A_BOLD)
|
||||||
curses.refresh()
|
curses.refresh()
|
||||||
end
|
end
|
||||||
]],
|
]==],
|
||||||
menu = [[menu = {Enter="increment"}]],
|
menu = [==[menu = {Enter="increment"}]==],
|
||||||
update = [[
|
update = [==[
|
||||||
function update(window)
|
function update(window)
|
||||||
local key = curses.getch()
|
local key = curses.getch()
|
||||||
if key == 10 then
|
if key == 10 then
|
||||||
n = n+1
|
n = n+1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
]],
|
]==],
|
||||||
main = [[
|
main = [==[
|
||||||
function main()
|
function main()
|
||||||
for i=1,7 do
|
for i=1,7 do
|
||||||
curses.init_pair(i, 0, i)
|
curses.init_pair(i, 0, i)
|
||||||
|
@ -33,5 +33,5 @@ function main()
|
||||||
update(window)
|
update(window)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
]],
|
]==],
|
||||||
}
|
}
|
||||||
|
|
44
hanoi.tlv
44
hanoi.tlv
|
@ -1,5 +1,5 @@
|
||||||
teliva_program = {
|
teliva_program = {
|
||||||
render = [[function render(window)
|
render = [==[function render(window)
|
||||||
window:clear()
|
window:clear()
|
||||||
local lines, cols = window:getmaxyx()
|
local lines, cols = window:getmaxyx()
|
||||||
local line = math.floor(lines/2)
|
local line = math.floor(lines/2)
|
||||||
|
@ -8,16 +8,16 @@ teliva_program = {
|
||||||
render_tower(window, line, i*col, i, t)
|
render_tower(window, line, i*col, i, t)
|
||||||
end
|
end
|
||||||
curses.refresh()
|
curses.refresh()
|
||||||
end]],
|
end]==],
|
||||||
lines = [[function lines(window)
|
lines = [==[function lines(window)
|
||||||
local lines, cols = window:getmaxyx()
|
local lines, cols = window:getmaxyx()
|
||||||
return lines
|
return lines
|
||||||
end]],
|
end]==],
|
||||||
pop = [[function pop(array)
|
pop = [==[function pop(array)
|
||||||
return table.remove(array)
|
return table.remove(array)
|
||||||
end]],
|
end]==],
|
||||||
window = [[window = curses.stdscr()]],
|
window = [==[window = curses.stdscr()]==],
|
||||||
render_tower = [[function render_tower(window, line, col, tower_index, tower)
|
render_tower = [==[function render_tower(window, line, col, tower_index, tower)
|
||||||
window:attron(curses.A_BOLD)
|
window:attron(curses.A_BOLD)
|
||||||
window:mvaddch(line+2, col, string.char(96+tower_index))
|
window:mvaddch(line+2, col, string.char(96+tower_index))
|
||||||
window:attroff(curses.A_BOLD)
|
window:attroff(curses.A_BOLD)
|
||||||
|
@ -34,9 +34,9 @@ end]],
|
||||||
window:attroff(curses.color_pair(7))
|
window:attroff(curses.color_pair(7))
|
||||||
line = line - 1
|
line = line - 1
|
||||||
end
|
end
|
||||||
end]],
|
end]==],
|
||||||
tower = [[tower = {{6, 5, 4, 3, 2}, {}, {}}]],
|
tower = [==[tower = {{6, 5, 4, 3, 2}, {}, {}}]==],
|
||||||
render_disk = [[function render_disk(window, line, col, size)
|
render_disk = [==[function render_disk(window, line, col, size)
|
||||||
col = col-size+1
|
col = col-size+1
|
||||||
for i=1,size do
|
for i=1,size do
|
||||||
window:attron(curses.color_pair(size))
|
window:attron(curses.color_pair(size))
|
||||||
|
@ -44,8 +44,8 @@ end]],
|
||||||
window:attroff(curses.color_pair(size))
|
window:attroff(curses.color_pair(size))
|
||||||
col = col+2
|
col = col+2
|
||||||
end
|
end
|
||||||
end]],
|
end]==],
|
||||||
main = [[function main()
|
main = [==[function main()
|
||||||
for i=1,7 do
|
for i=1,7 do
|
||||||
curses.init_pair(i, 0, i)
|
curses.init_pair(i, 0, i)
|
||||||
end
|
end
|
||||||
|
@ -55,27 +55,27 @@ end]],
|
||||||
update(window)
|
update(window)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
]],
|
]==],
|
||||||
len = [[function len(array)
|
len = [==[function len(array)
|
||||||
local result = 0
|
local result = 0
|
||||||
for k in pairs(array) do
|
for k in pairs(array) do
|
||||||
result = result+1
|
result = result+1
|
||||||
end
|
end
|
||||||
return result
|
return result
|
||||||
end]],
|
end]==],
|
||||||
update = [[function update(window)
|
update = [==[function update(window)
|
||||||
window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ")
|
window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ")
|
||||||
local from = curses.getch() - 96
|
local from = curses.getch() - 96
|
||||||
window:mvaddstr(lines(window)-1, 5, "tower to stack it on? ")
|
window:mvaddstr(lines(window)-1, 5, "tower to stack it on? ")
|
||||||
local to = curses.getch() - 96
|
local to = curses.getch() - 96
|
||||||
make_move(from, to)
|
make_move(from, to)
|
||||||
end]],
|
end]==],
|
||||||
make_move = [[function make_move(from, to)
|
make_move = [==[function make_move(from, to)
|
||||||
local disk = pop(tower[from])
|
local disk = pop(tower[from])
|
||||||
table.insert(tower[to], disk)
|
table.insert(tower[to], disk)
|
||||||
end]],
|
end]==],
|
||||||
cols = [[function cols(window)
|
cols = [==[function cols(window)
|
||||||
local lines, cols = window:getmaxyx()
|
local lines, cols = window:getmaxyx()
|
||||||
return cols
|
return cols
|
||||||
end]],
|
end]==],
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,9 +345,9 @@ static void save_image (lua_State *L) {
|
||||||
for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) {
|
for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) {
|
||||||
const char* key = lua_tostring(L, -2);
|
const char* key = lua_tostring(L, -2);
|
||||||
const char* value = lua_tostring(L, -1);
|
const char* value = lua_tostring(L, -1);
|
||||||
fprintf(fp, " %s = [[", key);
|
fprintf(fp, " %s = [==[", key);
|
||||||
fprintf(fp, "%s", value);
|
fprintf(fp, "%s", value);
|
||||||
fprintf(fp, "]],\n");
|
fprintf(fp, "]==],\n");
|
||||||
}
|
}
|
||||||
fprintf(fp, "}\n");
|
fprintf(fp, "}\n");
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
Loading…
Reference in New Issue