Merge pull request #408 from Xertis/patch-1

Fixing the table.copy bug
This commit is contained in:
MihailRis 2024-12-09 19:00:10 +03:00 committed by GitHub
commit 19908c4644
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 0 deletions

View File

@ -10,6 +10,12 @@ table.copy(t: table) -> table
Создаёт и возвращает копию переданной таблицы путём создания новой и копирования в неё всех элементов из переданной.
```lua
table.deep_copy(t: table) -> table
```
Функция глубокого копирования создает полную копию исходной таблицы, включая все её вложенные таблицы.
```lua
table.count_pairs(t: table) -> integer
```

View File

@ -63,6 +63,20 @@ function table.copy(t)
return copied
end
function table.deep_copy(t)
local copied = {}
for k, v in pairs(t) do
if type(v) == "table" then
copied[k] = table.deep_copy(v)
else
copied[k] = v
end
end
return copied
end
function table.count_pairs(t)
local count = 0