From 3e69e1b8c1dd954e8dffee2b230175bf1191b428 Mon Sep 17 00:00:00 2001 From: bol-van Date: Sun, 11 Jan 2026 11:21:12 +0300 Subject: [PATCH] zapret-lib: bitable --- docs/manual.en.md | 2 ++ docs/manual.md | 2 ++ lua/zapret-lib.lua | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/docs/manual.en.md b/docs/manual.en.md index c1754a0..59c374f 100644 --- a/docs/manual.en.md +++ b/docs/manual.en.md @@ -2256,10 +2256,12 @@ function blob_or_def(desync, name, def) ``` function barray(a, packer) function btable(a, packer) +function bitable(a, packer) ``` - `barray` uses only numeric indices starting from 1. The order is preserved. - `btable` uses all indices but does not guarantee order. +- `bitable` uses onlt numeric indices and guarantees order. Packs elements of array `a` in ascending order of index from 1 to the last. `packer` is a function that takes an element of `a` and returns a raw string. diff --git a/docs/manual.md b/docs/manual.md index 4d06bc0..122e5fe 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -2421,10 +2421,12 @@ function blob_or_def(desync, name, def) ``` function barray(a, packer) function btable(a, packer) +function bitable(a, packer) ``` - barray использует только числовые индексы, начиная с 1. порядок соблюдается - btable использует все индексы, но не гарантирует порядок +- bitable использует только числовые индексы от 1 и гарантирует порядок Упаковка элементов массива a в порядке возрастания индекса от 1 до последнего. `packer` - функция, берущая элемент a и возвращающая raw string. diff --git a/lua/zapret-lib.lua b/lua/zapret-lib.lua index 50140f1..5a2e381 100644 --- a/lua/zapret-lib.lua +++ b/lua/zapret-lib.lua @@ -330,6 +330,16 @@ function btable(a, packer) return s end end +-- convert table a to packed string using 'packer' function. numeric indexes only, ordered +function bitable(a, packer) + if a then + local s="" + for k,v in ipairs(a) do + s = s .. packer(v) + end + return s + end +end -- sequence comparision functions. they work only within 2G interval -- seq1>=seq2