Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new extensions #417

Merged
merged 6 commits into from
Dec 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions doc/ru/scripting/extensions.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ table.remove_value(t: table, x: object)

Удаляет элемент **x** из **t**.

```lua
table.shuffle(t: table) -> table
```

Перемешивает значения в таблице.


```lua
table.tostring(t: table) -> string
```
Expand Down Expand Up @@ -146,6 +153,18 @@ math.rand(low, high)

Возвращает случайное дробное число в диапазоне от **low** до **high**.

```lua
math.normalize(num: number, [опционально] conf: num) -> number
```

Возвращает нормализованное значение num относительно conf.

```lua
math.round(num: number, [опционально] places: num) -> number
```

Возвращает округлённое значение num до указанного количества знаков после запятой places.

## Дополнительные глобальные функции

В этом же скрипте также определены и другие глобальные функции которые доступны для использования. Ниже их список
Expand Down
22 changes: 22 additions & 0 deletions res/scripts/stdmin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,19 @@ function math.rand(low, high)
return low + (high - low) * math.random()
end

function math.normalize(num, conf)
conf = conf or 1

return (num / conf) % 1
end

function math.round(num, places)
places = places or 0

local mult = 10 ^ places
return math.floor(num * mult + 0.5) / mult
end

----------------------------------------------

function table.copy(t)
Expand Down Expand Up @@ -91,6 +104,15 @@ function table.random(t)
return t[math.random(1, #t)]
end

function table.shuffle(t)
for i = #t, 2, -1 do
local j = math.random(i)
t[i], t[j] = t[j], t[i]
end

return t
end

----------------------------------------------

local pattern_escape_replacements = {
Expand Down
Loading