NanosUtils
A table containing useful and aux functions.
👐Open Source
This structure is Open Sourced on GitHub. Feel free to make pull requests and suggest changes!
🗿Static Class
This is a Static Class. You can access it's methods directly with
.
. It is not possible to initialize or create new instances.🎒 Examples
local table = {
"my_key" = 123,
[2] = "my_value"
}
local dump_text = NanosUtils.Dump(table)
Console.Log(dump_text)
-- Outputs Text
--[[
{
"my_key": 123,
2 = "my_value"
}
--]]
local arg1 = math.random()
local arg2 = math.random()
NanosUtils.Benchmark("My Heavy Operation", 1000, function(param1, param2)
-- Do some heavy operations here
local result = param1 * param2
end, arg1, arg2)
-- Outputs Text: 'Benchmark 'My Heavy Operation' (x1000) took 1.5ms.'
🗿 Static Functions
Returns | Name | Description | |
---|---|---|---|
boolean | IsEntityValid | Returns if an entity is valid | |
string | Dump | Dumps a table into a readable text | |
Benchmark | Benchmarks a function performance | ||
string | FormatString | A better string.format | |
table | ShallowCopyTable | Performs a shallow copy of a table |
IsEntityValid
Returns if an entity is valid
Returns boolean (if the entity is valid)
local ret = NanosUtils.IsEntityValid(entity)
Type | Parameter | Default | Description |
---|---|---|---|
any | entity | Entity to verify |
Dump
Dumps a table into a readable text
Returns string (the table as readable text)
local ret = NanosUtils.Dump(table)
Type | Parameter | Default | Description |
---|---|---|---|
table | table | Table to dump |
Benchmark
Benchmarks a function performance, outputs in the console the elapsed time
NanosUtils.Benchmark(name, amount, func, args...)
Type | Parameter | Default | Description |
---|---|---|---|
string | name | Benchmark name to output | |
number | amount | Amount of times to loop | |
function | func | The function to call | |
any | args... | The arguments of the function to call |
FormatString
A better string.format. replace {num} by the corresponding vararg in a string
Example:NanosUtils.FormatString("Hello {2} I'm {1}", "a noob", "world!") -- "Hello world! I'm a noob"
Returns string (the final text with the arguments)
local ret = NanosUtils.FormatString(text, args...)
ShallowCopyTable
Performs a shallow copy of a table
Returns table (the copied table)
local ret = NanosUtils.ShallowCopyTable(table)
Type | Parameter | Default | Description |
---|---|---|---|
table | table | The table to shallow copy |