Skip to main content
Version: bleeding-edge 🩸

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

ReturnsNameDescription
boolean IsEntityValidReturns if an entity is valid
string DumpDumps a table into a readable text
BenchmarkBenchmarks a function performance
string FormatStringA better string.format
table ShallowCopyTablePerforms 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)
TypeParameterDefaultDescription
any entityEntity to verify

Dump

Dumps a table into a readable text

Returns string (the table as readable text)
local ret = NanosUtils.Dump(table)
TypeParameterDefaultDescription
table tableTable to dump

Benchmark

Benchmarks a function performance, outputs in the console the elapsed time
NanosUtils.Benchmark(name, amount, func, args...)
TypeParameterDefaultDescription
string nameBenchmark name to output
number amountAmount of times to loop
function funcThe 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...)
TypeParameterDefaultDescription
string textText to format
any args...The arguments to replace

ShallowCopyTable

Performs a shallow copy of a table

Returns table (the copied table)
local ret = NanosUtils.ShallowCopyTable(table)
TypeParameterDefaultDescription
table tableThe table to shallow copy