From 2bbeba0f932c8ba7fa04e5c4b7c5d8e220ae2ac3 Mon Sep 17 00:00:00 2001 From: Kseniia Antonova Date: Wed, 17 Aug 2022 07:26:31 +0300 Subject: [PATCH 1/4] fix example --- doc/reference/reference_lua/table.rst | 95 ++++++++++++++------------- 1 file changed, 49 insertions(+), 46 deletions(-) diff --git a/doc/reference/reference_lua/table.rst b/doc/reference/reference_lua/table.rst index 9083f0987a..a67edf2964 100644 --- a/doc/reference/reference_lua/table.rst +++ b/doc/reference/reference_lua/table.rst @@ -1,36 +1,36 @@ -.. _table-module: +.. _table-module: ------------------------------------------------------------------------------- Module table ------------------------------------------------------------------------------- -.. module:: table +.. module:: table -The :code:`table` module has everything in the -`standard Lua table library `_, -and some Tarantool extensions. + The :code:`table` module has everything in the + `standard Lua table library `_, + and some Tarantool extensions. -You can see this by saying "table": you will see this list of functions: -``clear`` (LuaJIT extension = erase all elements), -`concat `_ (concatenate), -``copy`` (make a copy of an array), -``deepcopy`` (see description below), -``foreach``, -``foreachi``, -`getn `_ (get the number of elements in an array), -`insert `_ (insert an element into an array), -`maxn `_ (get largest index) -`move `_ (move elements between tables), -``new`` (LuaJIT extension = return a new table with pre-allocated elements), -`remove `_ (remove an element from an array), -`sort `_ (sort the elements of an array). + You can see this by saying "table": you will see this list of functions: + ``clear`` (LuaJIT extension = erase all elements), + `concat `_ (concatenate), + ``copy`` (make a copy of an array), + ``deepcopy`` (see description below), + ``foreach``, + ``foreachi``, + `getn `_ (get the number of elements in an array), + `insert `_ (insert an element into an array), + `maxn `_ (get largest index) + `move `_ (move elements between tables), + ``new`` (LuaJIT extension = return a new table with pre-allocated elements), + `remove `_ (remove an element from an array), + `sort `_ (sort the elements of an array). -In this section we only discuss the additional function -that the Tarantool developers have added: ``deepcopy``. + In this section we only discuss the additional function + that the Tarantool developers have added: ``deepcopy``. -.. _table-deepcopy: +.. _table-deepcopy: -.. function:: deepcopy(input-table) +.. function:: deepcopy(input-table) Return a "deep" copy of the table -- a copy which follows nested structures to any depth and does not depend on pointers, @@ -60,41 +60,43 @@ that the Tarantool developers have added: ``deepcopy``. - b ... -.. _table-sort: +.. _table-sort: -.. function:: sort(input-table [, comparison-function]) +.. function:: sort(input-table [, comparison-function]) Put the input-table contents in sorted order. The `basic Lua table.sort `_ - has a default comparison-function: :code:`function (a, b) return a < b end`. + has a default comparison function: :code:`function (a, b) return a < b end`. That is efficient and standard. However, sometimes Tarantool users will want an equivalent to ``table.sort`` which has any of these features: - (1) If the table contains nils, except nils at the end, the results must still be correct. - That is not the case with the default tarantool_sort, and it cannot - be fixed by making a comparison that checks whether a and b are nil. - (Before trying certain Internet suggestions, test with - {1, nil, 2, -1, 44, 1e308, nil, 2, nil, nil, 0}. + #. If the table contains nils, except nils at the end, the results must still be correct. + That is not the case with the default ``tarantool_sort``, and it cannot + be fixed by making a comparison that checks whether ``a`` and ``b`` are ``nil``. + (Before trying certain Internet suggestions, test with + :code:`{1, nil, 2, -1, 44, 1e308, nil, 2, nil, nil, 0}`. - (2) If strings are to be sorted in a language-aware way, there must be a - parameter for collation. + #. If strings are to be sorted in a language-aware way, there must be a + parameter for collation. - (3) If the table has a mix of types, then they must be sorted as - booleans, then numbers, then strings, then byte arrays. + #. If the table has a mix of types, then they must be sorted as + booleans, then numbers, then strings, then byte arrays. - Since all those features are available in Tarantool spaces, - the solution for Tarantool is simple: make a temporary Tarantool - space, put the table contents into it, retrieve the tuples from it - in order, and overwrite the table. + Since all those features are available in Tarantool spaces, + the solution for Tarantool is simple: make a temporary Tarantool + space, put the table contents into it, retrieve the tuples from it + in order, and overwrite the table. - Here then is ``tarantool_sort()`` which does the same thing as - ``table.sort`` but has those extra features. It is not fast and - it requires a database privilege, so it should only be used if the - extra features are necessary. + Here then is ``tarantool_sort()`` which does the same thing as + ``table.sort`` but has those extra features. It is not fast and + it requires a database privilege, so it should only be used if the + extra features are necessary. - .. code-block:: none + **Example:** + + .. code-block:: tarantoolsession function tarantool_sort(input_table, collation) local c = collation or 'binary' @@ -118,5 +120,6 @@ that the Tarantool developers have added: ``deepcopy``. box.space[tmp_name]:drop() end - For example, suppose table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}. - After tarantool_sort(t, 'unicode_ci') t contains {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}. + + For example, suppose :code:`table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}`. + After ``tarantool_sort(t, 'unicode_ci')`` ``t`` contains :code:`{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}`. From f7006afbd739edb490d727aec8333651ae6d9144 Mon Sep 17 00:00:00 2001 From: Kseniia Antonova Date: Wed, 17 Aug 2022 07:55:19 +0300 Subject: [PATCH 2/4] fix formatting --- doc/reference/reference_lua/table.rst | 45 ++++++++++++++------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/doc/reference/reference_lua/table.rst b/doc/reference/reference_lua/table.rst index a67edf2964..307b88af5a 100644 --- a/doc/reference/reference_lua/table.rst +++ b/doc/reference/reference_lua/table.rst @@ -6,27 +6,28 @@ .. module:: table - The :code:`table` module has everything in the - `standard Lua table library `_, - and some Tarantool extensions. - - You can see this by saying "table": you will see this list of functions: - ``clear`` (LuaJIT extension = erase all elements), - `concat `_ (concatenate), - ``copy`` (make a copy of an array), - ``deepcopy`` (see description below), - ``foreach``, - ``foreachi``, - `getn `_ (get the number of elements in an array), - `insert `_ (insert an element into an array), - `maxn `_ (get largest index) - `move `_ (move elements between tables), - ``new`` (LuaJIT extension = return a new table with pre-allocated elements), - `remove `_ (remove an element from an array), - `sort `_ (sort the elements of an array). - - In this section we only discuss the additional function - that the Tarantool developers have added: ``deepcopy``. +The :code:`table` module has everything in the +`standard Lua table library `_, +and some Tarantool extensions. + +Write ``table`` to see the list of functions: + +* ``clear`` (LuaJIT extension = erase all elements) +* `concat `_ (concatenate) +* ``copy`` (make a copy of an array) +* ``deepcopy`` (see the :ref:`description ` below) +* ``foreach`` +* ``foreachi`` +* `getn `_ (get the number of elements in an array) +* `insert `_ (insert an element into an array) +* `maxn `_ (get the largest index) +* `move `_ (move elements between tables) +* ``new`` (LuaJIT extension = return a new table with pre-allocated elements) +* `remove `_ (remove an element from an array) +* `sort `_ (sort the elements of an array) + +In this section we only discuss the additional function +that the Tarantool developers have added: ``deepcopy``. .. _table-deepcopy: @@ -96,7 +97,7 @@ **Example:** - .. code-block:: tarantoolsession + .. code-block:: lua function tarantool_sort(input_table, collation) local c = collation or 'binary' From 52afac5d13801a36dafe63384be6cc4eabd001e7 Mon Sep 17 00:00:00 2001 From: Kseniia Antonova Date: Wed, 17 Aug 2022 08:22:58 +0300 Subject: [PATCH 3/4] update translation --- .../reference/reference_lua/table.po | 98 +++++++++---------- 1 file changed, 47 insertions(+), 51 deletions(-) diff --git a/locale/ru/LC_MESSAGES/reference/reference_lua/table.po b/locale/ru/LC_MESSAGES/reference/reference_lua/table.po index f8d10300e3..508bdd28fb 100644 --- a/locale/ru/LC_MESSAGES/reference/reference_lua/table.po +++ b/locale/ru/LC_MESSAGES/reference/reference_lua/table.po @@ -11,39 +11,35 @@ msgstr "" "некоторые расширения специально для Tarantool." msgid "" -"You can see this by saying \"table\": you will see this list of functions: " -"``clear`` (LuaJIT extension = erase all elements), `concat " -"`_ " -"(concatenate), ``copy`` (make a copy of an array), ``deepcopy`` (see " -"description below), ``foreach``, ``foreachi``, `getn " -"`_ (get the number of elements in an " -"array), `insert `_ (insert an element into an array), `maxn " -"`_ (get largest " -"index) `move `_ " -"(move elements between tables), ``new`` (LuaJIT extension = return a new " -"table with pre-allocated elements), `remove " -"`_ (remove an " -"element from an array), `sort " -"`_ (sort the " -"elements of an array)." +"Write ``table`` to see the list of functions: " +"``clear`` (LuaJIT extension = erase all elements)" +"`concat `_ (concatenate)" +"``copy`` (make a copy of an array)" +"``deepcopy`` (see the :ref:`description ` below)" +"``foreach``" +"``foreachi``" +"`getn `_ (get the number of elements in an array)" +"`insert `_ (insert an element into an array)" +"`maxn `_ (get еру largest index)" +"`move `_ (move elements between tables)" +"``new`` (LuaJIT extension = return a new table with pre-allocated elements)" +"`remove `_ (remove an element from an array) +"`sort `_ (sort the elements of an array)" msgstr "" -"Чтобы убедиться в этом, выполните команду \"table\": вы увидите список " -"функций: ``clear`` (расширение LuaJIT = удаление всех элементов), `concat " -"`_ " -"(конкатенация), ``copy`` (создание копии массива), ``deepcopy`` (см. " -"описание ниже), ``foreach``, ``foreachi``, `getn " -"`_ (получение количества элементов в " -"массиве), `insert `_ (вставка элемента в массив), `maxn " -"`_ (получение " -"самого большого индекса) `move " -"`_ (перемещение " -"элементов между таблицами), ``new`` (расширение LuaJIT = возврат новой " -"таблицы с предварительно выделенными элементами), `remove " -"`_ (удаление " -"элемента из массива), `sort `_ (сортировка элементов массива)." +"Чтобы убедиться в этом, выполните команду \"table\": вы увидите список функций: " +"``clear`` (расширение LuaJIT = удаление всех элементов)," +"`concat `_ (конкатенация)," +"``copy`` (создание копии массива)," +"``deepcopy`` (см. :ref:`описание ` ниже)," +"``foreach``," +"``foreachi``," +"`getn `_ (получение количества элементов в массиве)," +"`insert `_ (вставка элемента в массив)," +"`maxn `_ (получение самого большого индекса)," +"`move `_ (перемещение элементов между таблицами)," +"``new`` (расширение LuaJIT = возврат новой таблицы с предварительно выделенными элементами)," +"`remove `_ (удаление элемента из массива)," +"`sort `_ (сортировка элементов массива)." msgid "" "In this section we only discuss the additional function that the Tarantool " @@ -117,7 +113,7 @@ msgstr "Размещение содержимого введенной табл msgid "" "The `basic Lua table.sort `_ has a default comparison-function: :code:`function (a, b) " +"table.sort>`_ has a default comparison function: :code:`function (a, b) " "return a < b end`." msgstr "" "В базовой сортировке в Lua, `table.sort " @@ -133,31 +129,31 @@ msgstr "" "может понадобиться эквивалент ``table.sort`` со следующими функциями:" msgid "" -"(1) If the table contains nils, except nils at the end, the results must " -"still be correct. That is not the case with the default tarantool_sort, and " -"it cannot be fixed by making a comparison that checks whether a and b are " -"nil. (Before trying certain Internet suggestions, test with {1, nil, 2, -1, " -"44, 1e308, nil, 2, nil, nil, 0}." +"#. If the table contains nils, except nils at the end, the results must " +"still be correct. That is not the case with the default ``tarantool_sort``, and " +"it cannot be fixed by making a comparison that checks whether ``a`` and ``b`` are " +"``nil``. (Before trying certain Internet suggestions, test with :code:`{1, nil, 2, -1, " +"44, 1e308, nil, 2, nil, nil, 0}`." msgstr "" -"(1) Если таблица содержит нулевые значения, за исключением нулей в конце, " +"#. Если таблица содержит нулевые значения, за исключением нулей в конце, " "результаты все равно должны быть правильными. Это не работает при " -"использовании стандартного tarantool_sort, и это нельзя исправить, выполнив " -"сравнение, которое проверяет, равны ли значения a и b нулю. (Прежде чем " -"пробовать определенные предложения в Интернете, проверьте {1, nil, 2, -1, " -"44, 1e308, nil, 2, nil, nil, 0}." +"использовании стандартного ``tarantool_sort``, и это нельзя исправить, выполнив " +"сравнение, которое проверяет, равны ли значения ``a`` и ``b`` нулю. (Прежде чем " +"пробовать определенные предложения в Интернете, проверьте ``{1, nil, 2, -1, " +"44, 1e308, nil, 2, nil, nil, 0}``." msgid "" -"(2) If strings are to be sorted in a language-aware way, there must be a " +"#. If strings are to be sorted in a language-aware way, there must be a " "parameter for collation." msgstr "" -"(2) Если строки должны быть отсортированы с учетом языка, должен быть " +"#. Если строки должны быть отсортированы с учетом языка, должен быть " "параметр для сравнения символов." msgid "" -"(3) If the table has a mix of types, then they must be sorted as booleans, " +"#. If the table has a mix of types, then they must be sorted as booleans, " "then numbers, then strings, then byte arrays." msgstr "" -"(3) Если в таблица есть разные типы, то они должны быть отсортированы так: " +"#. Если в таблица есть разные типы, то они должны быть отсортированы так: " "логические, затем числа, затем строки, а затем байтовые массивы." msgid "" @@ -204,8 +200,8 @@ msgid "" " box.space[tmp_name]:drop()\n" " end\n" "\n" -"For example, suppose table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.\n" -"After tarantool_sort(t, 'unicode_ci') t contains {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}." +"For example, suppose :code:`table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}`.\n" +"After ``tarantool_sort(t, 'unicode_ci')`` ``t`` contains :code:`{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}`." msgstr "" "function tarantool_sort(input_table, collation)\n" " local c = collation or 'binary'\n" @@ -229,5 +225,5 @@ msgstr "" " box.space[tmp_name]:drop()\n" " end\n" "\n" -"Например, предположим, что таблица t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}.\n" -"После tarantool_sort(t, 'unicode_ci') t содержит {nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}." +"Например, предположим, что таблица ``t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}``.\n" +"После ``tarantool_sort(t, 'unicode_ci')`` ``t`` содержит ``{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}``." From 284c52792201776e23a6cb07cce690202ebf6edd Mon Sep 17 00:00:00 2001 From: Kseniia Antonova Date: Wed, 17 Aug 2022 11:26:17 +0300 Subject: [PATCH 4/4] minor update --- doc/reference/reference_lua/table.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/doc/reference/reference_lua/table.rst b/doc/reference/reference_lua/table.rst index 307b88af5a..e6f0791de3 100644 --- a/doc/reference/reference_lua/table.rst +++ b/doc/reference/reference_lua/table.rst @@ -85,15 +85,15 @@ that the Tarantool developers have added: ``deepcopy``. #. If the table has a mix of types, then they must be sorted as booleans, then numbers, then strings, then byte arrays. - Since all those features are available in Tarantool spaces, - the solution for Tarantool is simple: make a temporary Tarantool - space, put the table contents into it, retrieve the tuples from it - in order, and overwrite the table. + Since all those features are available in Tarantool spaces, + the solution for Tarantool is simple: make a temporary Tarantool + space, put the table contents into it, retrieve the tuples from it + in order, and overwrite the table. - Here then is ``tarantool_sort()`` which does the same thing as - ``table.sort`` but has those extra features. It is not fast and - it requires a database privilege, so it should only be used if the - extra features are necessary. + Here then is ``tarantool_sort()`` which does the same thing as + ``table.sort`` but has those extra features. It is not fast and + it requires a database privilege, so it should only be used if the + extra features are necessary. **Example:** @@ -123,4 +123,5 @@ that the Tarantool developers have added: ``deepcopy``. For example, suppose :code:`table t = {1, 'A', -88.3, nil, true, 'b', 'B', nil, 'À'}`. + After ``tarantool_sort(t, 'unicode_ci')`` ``t`` contains :code:`{nil, nil, true, -88.3, 1, 'A', 'À', 'b', 'B'}`.