Skip to main content
Version: latest - a1.7.0 βš–οΈ

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​

ReturnsNameDescription
booleanIsAReturns if an object is a type
stringDumpDumps a table into a readable text
BenchmarkBenchmarks a function performance

IsA​

Returns if an object is a type

Returns boolean

NanosUtils.IsA(object, type)
TypeParameterDescription
anyobjectObject to verify
anytypeType to verify

Dump​

Dumps a table into a readable text

Returns string

NanosUtils.Dump(table)
TypeParameterDescription
tabletableTable to dump

Benchmark​

Benchmarks a function performance, outputs in the console the elapsed time

NanosUtils.Benchmark(name, amount, func, args...)
TypeParameterDescription
stringnameBenchmark name to output
numberamountAmount of times to loop
functionfuncThe function to call
anyargs...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"

NanosUtils.FormatString(text, args...)
TypeParameterDescription
stringtextText to format
anyargs...The arguments to replace