use method syntax where possible

Perhaps this is a bad idea. It feels arbitrary, what methods Lua happens
to include in string and table objects without having to go through the
respective modules.
This commit is contained in:
Kartik K. Agaram 2022-03-06 16:38:49 -08:00
parent 5758f6c082
commit 6a3098d0e9
9 changed files with 80 additions and 80 deletions

View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,11 +32,11 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return table.concat(t)
> end > end
@ -186,7 +186,7 @@
count_letters: count_letters:
>function count_letters(s) >function count_letters(s)
> local result = {} > local result = {}
> for i=1,string.len(s) do > for i=1,s:len() do
> local c = s[i] > local c = s[i]
> if result[c] == nil then > if result[c] == nil then
> result[c] = 1 > result[c] = 1
@ -309,8 +309,8 @@
>Mon Feb 21 18:06:20 2022 >Mon Feb 21 18:06:20 2022
take_out: take_out:
>function take_out(s, i) >function take_out(s, i)
> if i < 1 then return string.sub(s, 1) end > if i < 1 then return s:sub(1) end
> return string.sub(s, 1, i-1) .. string.sub(s, i+1) > return s:sub(1, i-1) .. s:sub(i+1)
>end >end
> >
>function test_take_out() >function test_take_out()
@ -342,7 +342,7 @@
>Sat Mar 5 15:24:00 2022 >Sat Mar 5 15:24:00 2022
count_anagrams: count_anagrams:
>function count_anagrams(s) >function count_anagrams(s)
> local result = factorial(string.len(s)) > local result = factorial(s:len())
> local letter_counts = count_letters(s) > local letter_counts = count_letters(s)
> for k, v in pairs(letter_counts) do > for k, v in pairs(letter_counts) do
> result = result / factorial(v) > result = result / factorial(v)

View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,13 +32,13 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return t:concat()
> end > end
>end >end
> >

View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,11 +32,11 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return table.concat(t)
> end > end
@ -158,14 +158,14 @@
render_line: render_line:
>function render_line(window, y, line) >function render_line(window, y, line)
> window:mvaddstr(y, 0, '') > window:mvaddstr(y, 0, '')
> for i=1,string.len(line) do > for i=1,line:len() do
> window:addstr(line[i]) > window:addstr(line[i])
> end > end
>end >end
- __teliva_timestamp: original - __teliva_timestamp: original
render_link: render_link:
>function render_link(window, y, line) >function render_link(window, y, line)
> local rendered_line = string.gsub(line, '=>%s*%S*%s*', '') > local rendered_line = line:gsub('=>%s*%S*%s*', '')
> if trim(rendered_line) == '' then > if trim(rendered_line) == '' then
> rendered_line = line > rendered_line = line
> end > end
@ -189,7 +189,7 @@
> y = y+2 > y = y+2
>--? dbg(window, state.highlight_index) >--? dbg(window, state.highlight_index)
> for i, line in pairs(state.lines) do > for i, line in pairs(state.lines) do
> if not state.source and string.find(line, '=> ') == 1 then > if not state.source and line:find('=> ') == 1 then
> if state.highlight_index == 0 or i == state.highlight_index then > if state.highlight_index == 0 or i == state.highlight_index then
> -- highlighted link > -- highlighted link
> state.highlight_index = i -- TODO: ugly state update while rendering, just for first render after gemini_get > state.highlight_index = i -- TODO: ugly state update while rendering, just for first render after gemini_get
@ -276,7 +276,7 @@
- __teliva_timestamp: original - __teliva_timestamp: original
is_link: is_link:
>function is_link(line) >function is_link(line)
> return string.find(line, '=>%s*%S*%s*') == 1 > return line:find('=>%s*%S*%s*') == 1
>end >end
- __teliva_timestamp: original - __teliva_timestamp: original
next_link: next_link:
@ -384,11 +384,11 @@
> local s, status = tcp:receive() > local s, status = tcp:receive()
> if s == nil then break end > if s == nil then break end
> if s == '' then break end > if s == '' then break end
> local header, value = string.match(s, '(.-): (.*)') > local header, value = s:match('(.-): (.*)')
> if header == nil then > if header == nil then
> print(s) > print(s)
> else > else
> headers[string.lower(header)] = value > headers[header:lower()] = value
> print(header, value) > print(header, value)
> end > end
> end > end
@ -398,7 +398,7 @@
> local s, status = tcp:receive(bytes_remaining) > local s, status = tcp:receive(bytes_remaining)
> if s == nil then break end > if s == nil then break end
> body = body .. s > body = body .. s
> bytes_remaining = bytes_remaining - string.len(s) > bytes_remaining = bytes_remaining - s:len()
> if bytes_remaining <= 0 then break end > if bytes_remaining <= 0 then break end
> end > end
> return body > return body
@ -436,7 +436,7 @@
> if line == nil then break end > if line == nil then break end
> table.insert(state.lines, line) > table.insert(state.lines, line)
> end > end
> elseif string.sub(type, 1, 5) == 'text/' then > elseif type:sub(1, 5) == 'text/' then
> while true do > while true do
> local line, err = conn:receive() > local line, err = conn:receive()
> if line == nil then break end > if line == nil then break end
@ -450,7 +450,7 @@
>-- https://tildegit.org/solderpunk/gemini-demo-2 >-- https://tildegit.org/solderpunk/gemini-demo-2
>-- returns an array of lines, containing either the body or just an error >-- returns an array of lines, containing either the body or just an error
>function gemini_get(url) >function gemini_get(url)
> if string.find(url, "://") == nil then > if url:find("://") == nil then
> url = "gemini://" .. url > url = "gemini://" .. url
> end > end
> local parsed_url = socket.url.parse(url) > local parsed_url = socket.url.parse(url)
@ -480,7 +480,7 @@
> table.insert(state.lines, err) > table.insert(state.lines, err)
> return > return
> end > end
> local status, meta = string.match(line, "(%S+) (%S+)") > local status, meta = line:match("(%S+) (%S+)")
> if status[1] == '2' then > if status[1] == '2' then
> parse_gemini_body(conn, meta) > parse_gemini_body(conn, meta)
> state.url = url > state.url = url

View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,11 +32,11 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return table.concat(t)
> end > end
@ -202,7 +202,7 @@
count_letters: count_letters:
>function count_letters(s) >function count_letters(s)
> local result = {} > local result = {}
> for i=1,string.len(s) do > for i=1,s:len() do
> local c = s[i] > local c = s[i]
> if result[c] == nil then > if result[c] == nil then
> result[c] = 1 > result[c] = 1
@ -255,7 +255,7 @@
> end > end
> end > end
> h.addstr = function(self, s) > h.addstr = function(self, s)
> for i=1,string.len(s) do > for i=1,s:len() do
> self:addch(s[i]) > self:addch(s[i])
> end > end
> end > end
@ -275,7 +275,7 @@
kbd: kbd:
>function kbd(keys) >function kbd(keys)
> local result = {} > local result = {}
> for i=1,string.len(keys) do > for i=1,keys:len() do
> table.insert(result, keys[i]) > table.insert(result, keys[i])
> end > end
> return result > return result
@ -298,7 +298,7 @@
check_screen: check_screen:
>function check_screen(window, contents, message) >function check_screen(window, contents, message)
> local x, y = 1, 1 > local x, y = 1, 1
> for i=1,string.len(contents) do > for i=1,contents:len() do
> check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x) > check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x)
> x = x+1 > x = x+1
> if x > window.scr.w then > if x > window.scr.w then
@ -438,7 +438,7 @@
- __teliva_timestamp: original - __teliva_timestamp: original
state: state:
>function state(line, col) >function state(line, col)
> if line < 1 or line > table.getn(grid) or col < 1 or col > table.getn(grid[1]) then > if line < 1 or line > #grid or col < 1 or col > #grid[1] then
> return 0 > return 0
> end > end
> return grid[line][col] > return grid[line][col]
@ -454,9 +454,9 @@
step: step:
>function step() >function step()
> local new_grid = {} > local new_grid = {}
> for line=1,table.getn(grid) do > for line=1,#grid do
> new_grid[line] = {} > new_grid[line] = {}
> for col=1,table.getn(grid[1]) do > for col=1,#grid[1] do
> local n = num_live_neighbors(line, col) > local n = num_live_neighbors(line, col)
> if n == 3 then > if n == 3 then
> new_grid[line][col] = 1 > new_grid[line][col] = 1

View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,11 +32,11 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return table.concat(t)
> end > end

View File

@ -56,9 +56,9 @@ function character_splitting_task(chanin, chanout)
while true do while true do
local line = chanin:recv() local line = chanin:recv()
if line == nil then break end if line == nil then break end
local linesz = string.len(line) local linesz = line:len()
for i=1,linesz do for i=1,linesz do
chanout:send(string.sub(line, i, i)) chanout:send(line:sub(i, i))
end end
end end
chanout:send(nil) -- end of file chanout:send(nil) -- end of file

View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,11 +32,11 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return table.concat(t)
> end > end
@ -201,7 +201,7 @@
count_letters: count_letters:
>function count_letters(s) >function count_letters(s)
> local result = {} > local result = {}
> for i=1,string.len(s) do > for i=1,s:len() do
> local c = s[i] > local c = s[i]
> if result[c] == nil then > if result[c] == nil then
> result[c] = 1 > result[c] = 1
@ -257,7 +257,7 @@
> end > end
> end > end
> h.addstr = function(self, s) > h.addstr = function(self, s)
> for i=1,string.len(s) do > for i=1,s:len() do
> self:addch(s[i]) > self:addch(s[i])
> end > end
> end > end
@ -277,7 +277,7 @@
kbd: kbd:
>function kbd(keys) >function kbd(keys)
> local result = {} > local result = {}
> for i=1,string.len(keys) do > for i=1,keys:len() do
> table.insert(result, keys[i]) > table.insert(result, keys[i])
> end > end
> return result > return result
@ -299,7 +299,7 @@
check_screen: check_screen:
>function check_screen(window, contents, message) >function check_screen(window, contents, message)
> local x, y = 1, 1 > local x, y = 1, 1
> for i=1,string.len(contents) do > for i=1,contents:len() do
> check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x) > check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x)
> x = x+1 > x = x+1
> if x > window.scr.w then > if x > window.scr.w then

View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,11 +32,11 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return table.concat(t)
> end > end
@ -235,7 +235,7 @@
> pos = render_text(window, toot, pos, cursor) > pos = render_text(window, toot, pos, cursor)
> print('') > print('')
> window:attron(curses.A_BOLD) > window:attron(curses.A_BOLD)
> window:addstr(string.len(toot)) > window:addstr(toot:len())
> window:attroff(curses.A_BOLD) > window:attroff(curses.A_BOLD)
> end > end
> window:refresh() > window:refresh()
@ -244,7 +244,7 @@
render_delimiter: render_delimiter:
>function render_delimiter(window, s, pos, cursor) >function render_delimiter(window, s, pos, cursor)
> local newpos = pos > local newpos = pos
> for i=1,string.len(s) do > for i=1,s:len() do
> if newpos == cursor and i ~= 1 then > if newpos == cursor and i ~= 1 then
> if s[i] == '\n' then > if s[i] == '\n' then
> -- newline at cursor = render extra space in reverse video before jumping to new line > -- newline at cursor = render extra space in reverse video before jumping to new line
@ -290,7 +290,7 @@
>function render_text(window, s, pos, cursor) >function render_text(window, s, pos, cursor)
> local newpos = pos > local newpos = pos
>--? dbg(window, '--') >--? dbg(window, '--')
> for i=1,string.len(s) do > for i=1,s:len() do
>--? dbg(window, tostring(newpos)..' '..tostring(string.byte(s[i]))) >--? dbg(window, tostring(newpos)..' '..tostring(string.byte(s[i])))
> if newpos == cursor then > if newpos == cursor then
>--? dbg(window, 'cursor: '..tostring(cursor)) >--? dbg(window, 'cursor: '..tostring(cursor))

56
zet.tlv
View File

@ -23,7 +23,7 @@
>-- index characters using [] >-- index characters using []
>getmetatable('').__index = function(str,i) >getmetatable('').__index = function(str,i)
> if type(i) == 'number' then > if type(i) == 'number' then
> return string.sub(str,i,i) > return str:sub(i,i)
> else > else
> return string[i] > return string[i]
> end > end
@ -32,11 +32,11 @@
>-- ranges using (), selected bytes using {} >-- ranges using (), selected bytes using {}
>getmetatable('').__call = function(str,i,j) >getmetatable('').__call = function(str,i,j)
> if type(i)~='table' then > if type(i)~='table' then
> return string.sub(str,i,j) > return str:sub(i,j)
> else > else
> local t={} > local t={}
> for k,v in ipairs(i) do > for k,v in ipairs(i) do
> t[k]=string.sub(str,v,v) > t[k]=str:sub(v,v)
> end > end
> return table.concat(t) > return table.concat(t)
> end > end
@ -201,7 +201,7 @@
count_letters: count_letters:
>function count_letters(s) >function count_letters(s)
> local result = {} > local result = {}
> for i=1,string.len(s) do > for i=1,s:len() do
> local c = s[i] > local c = s[i]
> if result[c] == nil then > if result[c] == nil then
> result[c] = 1 > result[c] = 1
@ -259,7 +259,7 @@
> end > end
> end > end
> h.addstr = function(self, s) > h.addstr = function(self, s)
> for i=1,string.len(s) do > for i=1,s:len() do
> self:addch(s[i]) > self:addch(s[i])
> end > end
> end > end
@ -279,7 +279,7 @@
kbd: kbd:
>function kbd(keys) >function kbd(keys)
> local result = {} > local result = {}
> for i=1,string.len(keys) do > for i=1,keys:len() do
> table.insert(result, keys[i]) > table.insert(result, keys[i])
> end > end
> return result > return result
@ -301,7 +301,7 @@
check_screen: check_screen:
>function check_screen(window, contents, message) >function check_screen(window, contents, message)
> local x, y = 1, 1 > local x, y = 1, 1
> for i=1,string.len(contents) do > for i=1,contents:len() do
> check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x) > check_eq(contents[i], window.scr[y][x], message..'/'..y..','..x)
> x = x+1 > x = x+1
> if x > window.scr.w then > if x > window.scr.w then
@ -595,7 +595,7 @@
> end > end
> local y, x = top, left + 1 -- left padding; TODO: indent > local y, x = top, left + 1 -- left padding; TODO: indent
> window:mvaddstr(y, x, '') > window:mvaddstr(y, x, '')
> for i=1,string.len(s) do > for i=1,s:len() do
> -- render character > -- render character
> if i == cursor then > if i == cursor then
> if s[i] == '\n' then > if s[i] == '\n' then
@ -635,7 +635,7 @@
> end > end
> end > end
> end > end
> if cursor > string.len(s) then > if cursor > s:len() then
> window:attron(curses.A_REVERSE) > window:attron(curses.A_REVERSE)
> window:addch(' ') > window:addch(' ')
> window:attroff(curses.A_REVERSE) > window:attroff(curses.A_REVERSE)
@ -676,7 +676,7 @@
- __teliva_timestamp: original - __teliva_timestamp: original
cursor_down: cursor_down:
>function cursor_down(s, old_idx, width) >function cursor_down(s, old_idx, width)
> local max = string.len(s) > local max = s:len()
> local i = 1 > local i = 1
> -- compute oldcol, the screen column of old_idx > -- compute oldcol, the screen column of old_idx
> local oldcol = 0 > local oldcol = 0
@ -767,7 +767,7 @@
>initial commit: show/edit zettels >initial commit: show/edit zettels
cursor_up: cursor_up:
>function cursor_up(s, old_idx, width) >function cursor_up(s, old_idx, width)
> local max = string.len(s) > local max = s:len()
> local i = 1 > local i = 1
> -- compute oldcol, the screen column of old_idx > -- compute oldcol, the screen column of old_idx
> local oldcol = 0 > local oldcol = 0
@ -969,7 +969,7 @@
> end > end
> local y, x = top, left + 1 -- left padding; TODO: indent > local y, x = top, left + 1 -- left padding; TODO: indent
> window:mvaddstr(y, x, '') > window:mvaddstr(y, x, '')
> for i=1,string.len(s) do > for i=1,s:len() do
> if i == cursor then > if i == cursor then
> cursor_y = y > cursor_y = y
> cursor_x = x > cursor_x = x
@ -1010,7 +1010,7 @@
> local bottom = top + view_settings.height > local bottom = top + view_settings.height
> local left = (render_state.curr_w - 1) * (view_settings.width + view_settings.hmargin) > local left = (render_state.curr_w - 1) * (view_settings.width + view_settings.hmargin)
> local right = left + view_settings.width > local right = left + view_settings.width
> local cursor = string.len(zettels[current_zettel_id].data)+1 > local cursor = zettels[current_zettel_id].data:len()+1
> local quit = false > local quit = false
> curses.curs_set(1) > curses.curs_set(1)
> while not quit do > while not quit do
@ -2482,7 +2482,7 @@
> end > end
> local y, x = top, left + 1 -- left padding; TODO: indent > local y, x = top, left + 1 -- left padding; TODO: indent
> window:mvaddstr(y, x, '') > window:mvaddstr(y, x, '')
> for i=1,string.len(s) do > for i=1,s:len() do
> if i == cursor then > if i == cursor then
> cursor_y = y > cursor_y = y
> cursor_x = x > cursor_x = x
@ -2744,12 +2744,12 @@
> {'^l', 'line>>'}, > {'^l', 'line>>'},
> {'^k', 'del to line>>'}, > {'^k', 'del to line>>'},
> } > }
> local old_data = string.sub(zettels[current_zettel_id].data, 1) > local old_data = zettels[current_zettel_id].data:sub(1)
> local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin) > local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin)
> local bottom = top + view_settings.height > local bottom = top + view_settings.height
> local left = (render_state.curr_w - 1) * (view_settings.width + view_settings.hmargin) > local left = (render_state.curr_w - 1) * (view_settings.width + view_settings.hmargin)
> local right = left + view_settings.width > local right = left + view_settings.width
> local cursor = string.len(zettels[current_zettel_id].data)+1 > local cursor = zettels[current_zettel_id].data:len()+1
> local quit = false > local quit = false
> curses.curs_set(1) > curses.curs_set(1)
> while not quit do > while not quit do
@ -2791,7 +2791,7 @@
> cursor = cursor-1 > cursor = cursor-1
> end > end
> elseif key == 12 then -- ctrl-l > elseif key == 12 then -- ctrl-l
> local max = string.len(prose) > local max = prose:len()
> while cursor <= max and prose[cursor] ~= '\n' do > while cursor <= max and prose[cursor] ~= '\n' do
> cursor = cursor+1 > cursor = cursor+1
> end > end
@ -2799,7 +2799,7 @@
> elseif key == 2 then -- ctrl-b > elseif key == 2 then -- ctrl-b
> -- delete > -- delete
> elseif key == 11 then -- ctrl-k > elseif key == 11 then -- ctrl-k
> while cursor <= string.len(prose) and prose[cursor] ~= '\n' do > while cursor <= prose:len() and prose[cursor] ~= '\n' do
> prose = prose:remove(cursor) > prose = prose:remove(cursor)
> end > end
> -- exit > -- exit
@ -2848,33 +2848,33 @@
> end > end
> elseif key == 12 then -- ctrl-l > elseif key == 12 then -- ctrl-l
> -- to end of line > -- to end of line
> local max = string.len(prose) > local max = prose:len()
> while cursor <= max and prose[cursor] ~= '\n' do > while cursor <= max and prose[cursor] ~= '\n' do
> cursor = cursor+1 > cursor = cursor+1
> end > end
> elseif key == 6 then -- ctrl-f > elseif key == 6 then -- ctrl-f
> -- to next word > -- to next word
> local max = string.len(prose) > local max = prose:len()
> while cursor <= max and string.match(prose[cursor], '%w') do > while cursor <= max and prose[cursor]:match('%w') do
> cursor = cursor+1 > cursor = cursor+1
> end > end
> while cursor <= max and string.match(prose[cursor], '%W') do > while cursor <= max and prose[cursor]:match('%W') do
> cursor = cursor+1 > cursor = cursor+1
> end > end
> elseif key == 2 then -- ctrl-b > elseif key == 2 then -- ctrl-b
> -- to previous word > -- to previous word
> if cursor > string.len(prose) then > if cursor > prose:len() then
> cursor = string.len(prose) > cursor = prose:len()
> end > end
> while cursor > 1 and string.match(prose[cursor], '%W') do > while cursor > 1 and prose[cursor]:match('%W') do
> cursor = cursor-1 > cursor = cursor-1
> end > end
> while cursor > 1 and string.match(prose[cursor], '%w') do > while cursor > 1 and prose[cursor]:match('%w') do
> cursor = cursor-1 > cursor = cursor-1
> end > end
> -- delete > -- delete
> elseif key == 11 then -- ctrl-k > elseif key == 11 then -- ctrl-k
> while cursor <= string.len(prose) and prose[cursor] ~= '\n' do > while cursor <= prose:len() and prose[cursor] ~= '\n' do
> prose = prose:remove(cursor) > prose = prose:remove(cursor)
> end > end
> -- exit > -- exit
@ -2906,7 +2906,7 @@
> end > end
> local y, x = top, left + 1 -- left padding; TODO: indent > local y, x = top, left + 1 -- left padding; TODO: indent
> window:mvaddstr(y, x, '') > window:mvaddstr(y, x, '')
> for i=1,string.len(s) do > for i=1,s:len() do
> if i == cursor then > if i == cursor then
> cursor_y = y > cursor_y = y
> cursor_x = x > cursor_x = x