NanosUtils
A table containing useful and aux functions
info
Tip: This structure is Open Sourced at https://github.com/nanos-world/nanos-world-lua-lib. Feel free to push merge requests and suggest changes!
Usageβ
local table = {
"my_key" = 123,
[2] = "my_value"
}
local dump_text = NanosUtils.Dump(table)
Package.Log(dump_text)
-- Outputs Text
--[[
{
"my_key": 123,
2 = "my_value"
}
--]]
local my_variable = Character()
NanosUtils.IsA(my_variable, Character) -- true
NanosUtils.IsA(my_variable, Vehicle) -- false
Static Functionsβ
Returns | Name | Description |
---|---|---|
boolean | IsA | Returns if an object is a type |
string | Dump | Dumps a table into a readable text |
Benchmark | Benchmarks a function performance |
IsA
β
Returns if an object is a type
Returns boolean
NanosUtils.IsA(object, type)
Type | Parameter | Description |
---|---|---|
any | object | Object to verify |
any | type | Type to verify |
Dump
β
Dumps a table into a readable text
Returns string
NanosUtils.Dump(table)
Type | Parameter | 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 | 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 stringExample:
NanosUtils.FormatString("Hello {2} I'm {1}", "a noob", "world!") -- "Hello world! I'm a noob"
NanosUtils.FormatString(text, args...)
Type | Parameter | Description |
---|---|---|
string | text | Text to format |
any | args... | The arguments to replace |