diff --git a/counter.tlv b/counter.tlv index 3796f13..036f412 100644 --- a/counter.tlv +++ b/counter.tlv @@ -1,7 +1,7 @@ teliva_program = { - window = [[window = curses.stdscr()]], - n = [[n = 0]], - render = [[ + window = [==[window = curses.stdscr()]==], + n = [==[n = 0]==], + render = [==[ function render(window) window:clear() window:attron(curses.A_BOLD) @@ -12,17 +12,17 @@ function render(window) window:attroff(curses.A_BOLD) curses.refresh() end - ]], - menu = [[menu = {Enter="increment"}]], - update = [[ + ]==], + menu = [==[menu = {Enter="increment"}]==], + update = [==[ function update(window) local key = curses.getch() if key == 10 then n = n+1 end end - ]], - main = [[ + ]==], + main = [==[ function main() for i=1,7 do curses.init_pair(i, 0, i) @@ -33,5 +33,5 @@ function main() update(window) end end - ]], + ]==], } 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]==], } diff --git a/src/lua.c b/src/lua.c index 7108fa7..ae1e203 100644 --- a/src/lua.c +++ b/src/lua.c @@ -345,9 +345,9 @@ static void save_image (lua_State *L) { for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1)) { const char* key = lua_tostring(L, -2); const char* value = lua_tostring(L, -1); - fprintf(fp, " %s = [[", key); + fprintf(fp, " %s = [==[", key); fprintf(fp, "%s", value); - fprintf(fp, "]],\n"); + fprintf(fp, "]==],\n"); } fprintf(fp, "}\n"); fclose(fp);