idiom: table.insert for appending
Stop using arr[#arr+1].
This commit is contained in:
parent
a05f713dc1
commit
c21cefa888
|
@ -207,7 +207,7 @@
|
||||||
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
||||||
>function append(l, elems)
|
>function append(l, elems)
|
||||||
> for i=1,#elems do
|
> for i=1,#elems do
|
||||||
> l[#l+1] = elems[i]
|
> table.insert(l, elems[i])
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
@ -336,7 +336,7 @@
|
||||||
> if #l == 0 then return {prefix} end
|
> if #l == 0 then return {prefix} end
|
||||||
> local result = {}
|
> local result = {}
|
||||||
> for _, elem in ipairs(l) do
|
> for _, elem in ipairs(l) do
|
||||||
> result[#result+1] = prefix..elem
|
> table.insert(result, prefix..elem)
|
||||||
> end
|
> end
|
||||||
> return result
|
> return result
|
||||||
>end
|
>end
|
||||||
|
|
14
break.tlv
14
break.tlv
|
@ -237,7 +237,7 @@
|
||||||
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
||||||
>function append(l, elems)
|
>function append(l, elems)
|
||||||
> for i=1,#elems do
|
> for i=1,#elems do
|
||||||
> l[#l+1] = elems[i]
|
> table.insert(l, elems[i])
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
@ -625,11 +625,11 @@
|
||||||
update:
|
update:
|
||||||
>function update(window)
|
>function update(window)
|
||||||
> local key = string.char(window:getch())
|
> local key = string.char(window:getch())
|
||||||
> local nwords = #program.lines[1].words
|
|
||||||
> if key == ' ' then
|
> if key == ' ' then
|
||||||
> program.lines[1].words[nwords+1] = {data='', cursor=0}
|
> table.insert(program.lines[1].words, {data='', cursor=0})
|
||||||
> else
|
> else
|
||||||
> program.lines[1].words[nwords].data = program.lines[1].words[nwords].data .. key
|
> local words = program.lines[1].words
|
||||||
|
> words[#words].data = words[#words].data .. key
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp:
|
- __teliva_timestamp:
|
||||||
|
@ -682,11 +682,11 @@
|
||||||
>Thu Mar 17 21:43:20 2022
|
>Thu Mar 17 21:43:20 2022
|
||||||
update:
|
update:
|
||||||
>function update(window, program, key)
|
>function update(window, program, key)
|
||||||
> local nwords = #program.lines[1].words
|
|
||||||
> if key == ' ' then
|
> if key == ' ' then
|
||||||
> program.lines[1].words[nwords+1] = {data='', cursor=0}
|
> table.insert(program.lines[1].words, {data='', cursor=0})
|
||||||
> else
|
> else
|
||||||
> program.lines[1].words[nwords].data = program.lines[1].words[nwords].data .. key
|
> local words = program.lines[1].words
|
||||||
|
> words[#words].data = words[#words].data .. key
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp:
|
- __teliva_timestamp:
|
||||||
|
|
|
@ -237,7 +237,7 @@
|
||||||
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
||||||
>function append(l, elems)
|
>function append(l, elems)
|
||||||
> for i=1,#elems do
|
> for i=1,#elems do
|
||||||
> l[#l+1] = elems[i]
|
> table.insert(l, elems[i])
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
@ -814,7 +814,7 @@
|
||||||
> local result = {}
|
> local result = {}
|
||||||
> for source, _ in pairs(Graph) do
|
> for source, _ in pairs(Graph) do
|
||||||
> if not is_target[source] then
|
> if not is_target[source] then
|
||||||
> result[#result+1] = source
|
> table.insert(result, source)
|
||||||
> end
|
> end
|
||||||
> end
|
> end
|
||||||
> return result
|
> return result
|
||||||
|
|
2
life.tlv
2
life.tlv
|
@ -237,7 +237,7 @@
|
||||||
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
||||||
>function append(l, elems)
|
>function append(l, elems)
|
||||||
> for i=1,#elems do
|
> for i=1,#elems do
|
||||||
> l[#l+1] = elems[i]
|
> table.insert(l, elems[i])
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
|
|
@ -237,7 +237,7 @@
|
||||||
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
||||||
>function append(l, elems)
|
>function append(l, elems)
|
||||||
> for i=1,#elems do
|
> for i=1,#elems do
|
||||||
> l[#l+1] = elems[i]
|
> table.insert(l, elems[i])
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
|
2
zet.tlv
2
zet.tlv
|
@ -237,7 +237,7 @@
|
||||||
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
>-- concatenate list 'elems' into 'l', modifying 'l' in the process
|
||||||
>function append(l, elems)
|
>function append(l, elems)
|
||||||
> for i=1,#elems do
|
> for i=1,#elems do
|
||||||
> l[#l+1] = elems[i]
|
> table.insert(l, elems[i])
|
||||||
> end
|
> end
|
||||||
>end
|
>end
|
||||||
- __teliva_timestamp: original
|
- __teliva_timestamp: original
|
||||||
|
|
Loading…
Reference in New Issue