Continuing to study Lua.
I wrote a function that removes the first sentence from each row and returns the result as a table of modified rows where the first sentence was deleted. Oddly enough, it table.insertbehaves strangely in such a function.
function mypackage.remove_first(table_of_lines)
local lns = table_of_lines
local new_lns = {}
for i=1,
table.insert(new_lns,string.gsub(lns[i],"^[^.]+. ","",1))
end
return new_lns
end
Suddenly this gave me the following error.
[string "function mypackage.remove_first(table_of_lines)..."]:5: bad argument #2 to 'insert' (number expected, got string)
Why is the "number expected" in the first place?
From table.insertdocs
Inserts the value of an element at the pos position in the list, shifting the list of elements [pos], the list [pos + 1], ···, list [#list]. The default value for pos is # list + 1, so there is a call table. insert (t, x) inserts x at the end of the list t.
Nothing is said about type requirements for table.insert. Ok, I decided to change the example.
function mypackage.remove_first(table_of_lines)
local lns = table_of_lines
local new_lns = {}
for i=1,
local nofirst = string.gsub(lns[i],"^[^.]+. ","",1)
table.insert(new_lns,nofirst)
end
return new_lns
end
. , ?