Math
v1.3.7Shared Module — extends the global math table
All functions are added directly to the Lua math global. Accessible via math.* or lib.math.*.
math.round
Rounds a number to the specified decimal places.
| Parameter | Type | Required | Description |
|---|---|---|---|
| value | number | string | yes | Value to round |
| places | number | string | no | Decimal places (default: 0) |
math.clamp
Clamps a value between lower and upper bounds. Auto-swaps boundaries if inverted.
| Parameter | Type | Required | Description |
|---|---|---|---|
| val | number | yes | Value to clamp |
| lower | number | yes | Lower bound |
| upper | number | yes | Upper bound |
math.interp
Simple linear interpolation between two values.
| Parameter | Type | Required | Description |
|---|---|---|---|
| start | number | yes | Start value |
| finish | number | yes | End value |
| factor | number | yes | Interpolation factor (0–1) |
math.lerp
Returns an iterator that yields interpolated values each frame over a duration.
| Parameter | Type | Required | Description |
|---|---|---|---|
| start | number | vector | table | yes | Start value |
| finish | number | vector | table | yes | End value (same type as start) |
| duration | number | yes | Duration in milliseconds |
The final iteration yields (finish, 1), then nil.
math.groupdigits
Formats a number with digit grouping.
| Parameter | Type | Required | Description |
|---|---|---|---|
| number | number | string | yes | Number to format |
| separator | string | no | Separator character (default: ,) |
math.toscalars
Parses numeric scalars from a string.
| Parameter | Type | Required | Description |
|---|---|---|---|
| input | string | yes | String containing numeric values |
| min | number | no | Minimum clamp value |
| max | number | no | Maximum clamp value |
| round | boolean | number | no | true to round all, or number to only round the first N values |
math.tovector
Converts a string or table to a vector type.
| Parameter | Type | Required | Description |
|---|---|---|---|
| input | string | table | yes | Input value — tables support {x,y,z} or {x=,y=,z=} |
| min | number | no | Minimum clamp |
| max | number | no | Maximum clamp |
| round | boolean | number | no | Round flag |
Returns vector2, vector3, vector4, or number depending on the number of components.
math.normaltorotation
Converts a surface normal vector to a rotation vector.
math.torgba
Converts a string or table to an RGBA vector4.
RGB values are 0–255, alpha is 0–1.
math.hextorgb
Converts a hex colour string to RGB components.
math.tohex
Converts a number to a hex string.
| Parameter | Type | Required | Description |
|---|---|---|---|
| n | number | yes | Number to convert |
| upper | boolean | no | Use uppercase hex letters |