Skip to content

Commit d10b1f2

Browse files
authored
Fix example in module table (#3099)
fix formatting in example and text Fixes #3089
1 parent 334f7cd commit d10b1f2

File tree

2 files changed

+85
-84
lines changed
  • doc/reference/reference_lua
  • locale/ru/LC_MESSAGES/reference/reference_lua

2 files changed

+85
-84
lines changed

doc/reference/reference_lua/table.rst

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,37 @@
1-
.. _table-module:
1+
.. _table-module:
22

33
-------------------------------------------------------------------------------
44
Module table
55
-------------------------------------------------------------------------------
66

7-
.. module:: table
7+
.. module:: table
88

99
The :code:`table` module has everything in the
1010
`standard Lua table library <https://www.lua.org/manual/5.1/manual.html#5.5>`_,
1111
and some Tarantool extensions.
1212

13-
You can see this by saying "table": you will see this list of functions:
14-
``clear`` (LuaJIT extension = erase all elements),
15-
`concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (concatenate),
16-
``copy`` (make a copy of an array),
17-
``deepcopy`` (see description below),
18-
``foreach``,
19-
``foreachi``,
20-
`getn <https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an array),
21-
`insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (insert an element into an array),
22-
`maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get largest index)
23-
`move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (move elements between tables),
24-
``new`` (LuaJIT extension = return a new table with pre-allocated elements),
25-
`remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an element from an array),
26-
`sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the elements of an array).
13+
Write ``table`` to see the list of functions:
14+
15+
* ``clear`` (LuaJIT extension = erase all elements)
16+
* `concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (concatenate)
17+
* ``copy`` (make a copy of an array)
18+
* ``deepcopy`` (see the :ref:`description <table-deepcopy>` below)
19+
* ``foreach``
20+
* ``foreachi``
21+
* `getn <https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an array)
22+
* `insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (insert an element into an array)
23+
* `maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get the largest index)
24+
* `move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (move elements between tables)
25+
* ``new`` (LuaJIT extension = return a new table with pre-allocated elements)
26+
* `remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an element from an array)
27+
* `sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the elements of an array)
2728

2829
In this section we only discuss the additional function
2930
that the Tarantool developers have added: ``deepcopy``.
3031

31-
.. _table-deepcopy:
32+
.. _table-deepcopy:
3233

33-
.. function:: deepcopy(input-table)
34+
.. function:: deepcopy(input-table)
3435

3536
Return a "deep" copy of the table -- a copy which follows
3637
nested structures to any depth and does not depend on pointers,
@@ -60,29 +61,29 @@ that the Tarantool developers have added: ``deepcopy``.
6061
- b
6162
...
6263
63-
.. _table-sort:
64+
.. _table-sort:
6465

65-
.. function:: sort(input-table [, comparison-function])
66+
.. function:: sort(input-table [, comparison-function])
6667

6768
Put the input-table contents in sorted order.
6869

6970
The `basic Lua table.sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_
70-
has a default comparison-function: :code:`function (a, b) return a < b end`.
71+
has a default comparison function: :code:`function (a, b) return a < b end`.
7172

7273
That is efficient and standard. However, sometimes Tarantool users
7374
will want an equivalent to ``table.sort`` which has any of these features:
7475

75-
(1) If the table contains nils, except nils at the end, the results must still be correct.
76-
That is not the case with the default tarantool_sort, and it cannot
77-
be fixed by making a comparison that checks whether a and b are nil.
78-
(Before trying certain Internet suggestions, test with
79-
{1, nil, 2, -1, 44, 1e308, nil, 2, nil, nil, 0}.
76+
#. If the table contains nils, except nils at the end, the results must still be correct.
77+
That is not the case with the default ``tarantool_sort``, and it cannot
78+
be fixed by making a comparison that checks whether ``a`` and ``b`` are ``nil``.
79+
(Before trying certain Internet suggestions, test with
80+
:code:`{1, nil, 2, -1, 44, 1e308, nil, 2, nil, nil, 0}`.
8081

81-
(2) If strings are to be sorted in a language-aware way, there must be a
82-
parameter for collation.
82+
#. If strings are to be sorted in a language-aware way, there must be a
83+
parameter for collation.
8384

84-
(3) If the table has a mix of types, then they must be sorted as
85-
booleans, then numbers, then strings, then byte arrays.
85+
#. If the table has a mix of types, then they must be sorted as
86+
booleans, then numbers, then strings, then byte arrays.
8687

8788
Since all those features are available in Tarantool spaces,
8889
the solution for Tarantool is simple: make a temporary Tarantool
@@ -94,7 +95,9 @@ that the Tarantool developers have added: ``deepcopy``.
9495
it requires a database privilege, so it should only be used if the
9596
extra features are necessary.
9697

97-
.. code-block:: none
98+
**Example:**
99+
100+
.. code-block:: lua
98101
99102
function tarantool_sort(input_table, collation)
100103
local c = collation or 'binary'
@@ -118,5 +121,7 @@ that the Tarantool developers have added: ``deepcopy``.
118121
box.space[tmp_name]:drop()
119122
end
120123
121-
For example, suppose table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.
122-
After tarantool_sort(t, 'unicode_ci') t contains {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}.
124+
125+
For example, suppose :code:`table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}`.
126+
127+
After ``tarantool_sort(t, 'unicode_ci')`` ``t`` contains :code:`{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}`.

locale/ru/LC_MESSAGES/reference/reference_lua/table.po

Lines changed: 47 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -11,39 +11,35 @@ msgstr ""
1111
"некоторые расширения специально для Tarantool."
1212

1313
msgid ""
14-
"You can see this by saying \"table\": you will see this list of functions: "
15-
"``clear`` (LuaJIT extension = erase all elements), `concat "
16-
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ "
17-
"(concatenate), ``copy`` (make a copy of an array), ``deepcopy`` (see "
18-
"description below), ``foreach``, ``foreachi``, `getn "
19-
"<https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an "
20-
"array), `insert <https://www.lua.org/manual/5.1/manual.html#pdf-"
21-
"table.insert>`_ (insert an element into an array), `maxn "
22-
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get largest "
23-
"index) `move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ "
24-
"(move elements between tables), ``new`` (LuaJIT extension = return a new "
25-
"table with pre-allocated elements), `remove "
26-
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an "
27-
"element from an array), `sort "
28-
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the "
29-
"elements of an array)."
14+
"Write ``table`` to see the list of functions: "
15+
"``clear`` (LuaJIT extension = erase all elements)"
16+
"`concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (concatenate)"
17+
"``copy`` (make a copy of an array)"
18+
"``deepcopy`` (see the :ref:`description <table-deepcopy>` below)"
19+
"``foreach``"
20+
"``foreachi``"
21+
"`getn <https://www.lua.org/pil/19.1.html>`_ (get the number of elements in an array)"
22+
"`insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (insert an element into an array)"
23+
"`maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (get еру largest index)"
24+
"`move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (move elements between tables)"
25+
"``new`` (LuaJIT extension = return a new table with pre-allocated elements)"
26+
"`remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (remove an element from an array)
27+
"`sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (sort the elements of an array)"
3028
msgstr ""
31-
"Чтобы убедиться в этом, выполните команду \"table\": вы увидите список "
32-
"функций: ``clear`` (расширение LuaJIT = удаление всех элементов), `concat "
33-
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ "
34-
"(конкатенация), ``copy`` (создание копии массива), ``deepcopy`` (см. "
35-
"описание ниже), ``foreach``, ``foreachi``, `getn "
36-
"<https://www.lua.org/pil/19.1.html>`_ (получение количества элементов в "
37-
"массиве), `insert <https://www.lua.org/manual/5.1/manual.html#pdf-"
38-
"table.insert>`_ (вставка элемента в массив), `maxn "
39-
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (получение "
40-
"самого большого индекса) `move "
41-
"<https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (перемещение "
42-
"элементов между таблицами), ``new`` (расширение LuaJIT = возврат новой "
43-
"таблицы с предварительно выделенными элементами), `remove "
44-
"<https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (удаление "
45-
"элемента из массива), `sort <https://www.lua.org/manual/5.1/manual.html#pdf-"
46-
"table.sort>`_ (сортировка элементов массива)."
29+
"Чтобы убедиться в этом, выполните команду \"table\": вы увидите список функций: "
30+
"``clear`` (расширение LuaJIT = удаление всех элементов),"
31+
"`concat <https://www.lua.org/manual/5.1/manual.html#pdf-table.concat>`_ (конкатенация),"
32+
"``copy`` (создание копии массива),"
33+
"``deepcopy`` (см. :ref:`описание <table-deepcopy>` ниже),"
34+
"``foreach``,"
35+
"``foreachi``,"
36+
"`getn <https://www.lua.org/pil/19.1.html>`_ (получение количества элементов в массиве),"
37+
"`insert <https://www.lua.org/manual/5.1/manual.html#pdf-table.insert>`_ (вставка элемента в массив),"
38+
"`maxn <https://www.lua.org/manual/5.1/manual.html#pdf-table.maxn>`_ (получение самого большого индекса),"
39+
"`move <https://www.lua.org/manual/5.3/manual.html#pdf-table.move>`_ (перемещение элементов между таблицами),"
40+
"``new`` (расширение LuaJIT = возврат новой таблицы с предварительно выделенными элементами),"
41+
"`remove <https://www.lua.org/manual/5.1/manual.html#pdf-table.remove>`_ (удаление элемента из массива),"
42+
"`sort <https://www.lua.org/manual/5.1/manual.html#pdf-table.sort>`_ (сортировка элементов массива)."
4743

4844
msgid ""
4945
"In this section we only discuss the additional function that the Tarantool "
@@ -117,7 +113,7 @@ msgstr "Размещение содержимого введенной табл
117113

118114
msgid ""
119115
"The `basic Lua table.sort <https://www.lua.org/manual/5.1/manual.html#pdf-"
120-
"table.sort>`_ has a default comparison-function: :code:`function (a, b) "
116+
"table.sort>`_ has a default comparison function: :code:`function (a, b) "
121117
"return a < b end`."
122118
msgstr ""
123119
"В базовой сортировке в Lua, `table.sort "
@@ -133,31 +129,31 @@ msgstr ""
133129
"может понадобиться эквивалент ``table.sort`` со следующими функциями:"
134130

135131
msgid ""
136-
"(1) If the table contains nils, except nils at the end, the results must "
137-
"still be correct. That is not the case with the default tarantool_sort, and "
138-
"it cannot be fixed by making a comparison that checks whether a and b are "
139-
"nil. (Before trying certain Internet suggestions, test with {1, nil, 2, -1, "
140-
"44, 1e308, nil, 2, nil, nil, 0}."
132+
"#. If the table contains nils, except nils at the end, the results must "
133+
"still be correct. That is not the case with the default ``tarantool_sort``, and "
134+
"it cannot be fixed by making a comparison that checks whether ``a`` and ``b`` are "
135+
"``nil``. (Before trying certain Internet suggestions, test with :code:`{1, nil, 2, -1, "
136+
"44, 1e308, nil, 2, nil, nil, 0}`."
141137
msgstr ""
142-
"(1) Если таблица содержит нулевые значения, за исключением нулей в конце, "
138+
"#. Если таблица содержит нулевые значения, за исключением нулей в конце, "
143139
"результаты все равно должны быть правильными. Это не работает при "
144-
"использовании стандартного tarantool_sort, и это нельзя исправить, выполнив "
145-
"сравнение, которое проверяет, равны ли значения a и b нулю. (Прежде чем "
146-
"пробовать определенные предложения в Интернете, проверьте {1, nil, 2, -1, "
147-
"44, 1e308, nil, 2, nil, nil, 0}."
140+
"использовании стандартного ``tarantool_sort``, и это нельзя исправить, выполнив "
141+
"сравнение, которое проверяет, равны ли значения ``a`` и ``b`` нулю. (Прежде чем "
142+
"пробовать определенные предложения в Интернете, проверьте ``{1, nil, 2, -1, "
143+
"44, 1e308, nil, 2, nil, nil, 0}``."
148144

149145
msgid ""
150-
"(2) If strings are to be sorted in a language-aware way, there must be a "
146+
"#. If strings are to be sorted in a language-aware way, there must be a "
151147
"parameter for collation."
152148
msgstr ""
153-
"(2) Если строки должны быть отсортированы с учетом языка, должен быть "
149+
"#. Если строки должны быть отсортированы с учетом языка, должен быть "
154150
"параметр для сравнения символов."
155151

156152
msgid ""
157-
"(3) If the table has a mix of types, then they must be sorted as booleans, "
153+
"#. If the table has a mix of types, then they must be sorted as booleans, "
158154
"then numbers, then strings, then byte arrays."
159155
msgstr ""
160-
"(3) Если в таблица есть разные типы, то они должны быть отсортированы так: "
156+
"#. Если в таблица есть разные типы, то они должны быть отсортированы так: "
161157
"логические, затем числа, затем строки, а затем байтовые массивы."
162158

163159
msgid ""
@@ -204,8 +200,8 @@ msgid ""
204200
" box.space[tmp_name]:drop()\n"
205201
" end\n"
206202
"\n"
207-
"For example, suppose table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.\n"
208-
"After tarantool_sort(t, 'unicode_ci') t contains {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}."
203+
"For example, suppose :code:`table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}`.\n"
204+
"After ``tarantool_sort(t, 'unicode_ci')`` ``t`` contains :code:`{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}`."
209205
msgstr ""
210206
"function tarantool_sort(input_table, collation)\n"
211207
" local c = collation or 'binary'\n"
@@ -229,5 +225,5 @@ msgstr ""
229225
" box.space[tmp_name]:drop()\n"
230226
" end\n"
231227
"\n"
232-
"Например, предположим, что таблица t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.\n"
233-
"После tarantool_sort(t, 'unicode_ci') t содержит {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}."
228+
"Например, предположим, что таблица ``t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}``.\n"
229+
"После ``tarantool_sort(t, 'unicode_ci')`` ``t`` содержит ``{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}``."

0 commit comments

Comments
 (0)