Skip to content

Commit

Permalink
add table.slice
Browse files Browse the repository at this point in the history
  • Loading branch information
Xertis committed Jan 31, 2025
1 parent 6592684 commit 17ce49b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/ru/scripting/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ table.deep_flat(t: table) -> table

Возвращает глубокую "плоскую" версию исходной таблицы.

```lua
table.slice(arr: table, start: number | nil, stop: number | nil) -> table
```

Возвращает обрезанную версию таблицы с индекса **start** до индекса **stop** включительно, при этом пары ключ-значение не сохраняются в новой таблице. При значениях **nil** начинает с **1** и заканчивает **#arr** соответственно.

```lua
table.tostring(t: table) -> string
```
Expand Down
12 changes: 12 additions & 0 deletions res/scripts/stdmin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,18 @@ function table.deep_flat(t)

return flat
end

function table.slice(arr, start, stop)
local sliced = {}
start = start or 1
stop = stop or #arr

for i = start, stop do
table.insert(sliced, arr[i])
end

return sliced
end
----------------------------------------------

local pattern_escape_replacements = {
Expand Down

0 comments on commit 17ce49b

Please sign in to comment.