HolyLib Wiki

util

util

This library is part of gmod but were extenting it.
See: https://wiki.facepunch.com/gmod/util

Methods

util.AsyncCompress( string data, number level = 5, number dictSize = 65536, function callback )
Compresses the given data async. Instead of copying the given data, we keep a reference to it.
So don't modify it, while were compressing it!
util.AsyncDecompress( string data, function callback, number ratio = 0.98 )
Decompresses the given data async. Instead of copying the given data, we keep a reference to it.
So don't modify it, while were decompressing it!
util.AsyncTableToJSON( table tbl, function callback, boolean pretty )
Turns the given table into a json string just like util.FancyTableToJSON but it will do this on a different thread.
By giving the table to this function you make a promise to not modify the table while the json string is being created!
This is because we don't copy the table, we instead copy the pointer into a new Lua state where we then iterate/access it from another state/thread and if you modify it in any way you will experience a crash.
You still can access the table in that time, you are just not allowed to modify it.
It was observed that you can kinda modify the table though if you add new elements/the size of the table changes while its still creating the json string you will crash.
This function requires the luajit module to be enabled.
util.CompressLZ4( string data, number accelerationLevel = 1 )
Compresses the given data using LZ4
Decompresses the given data using LZ4
table util.FancyJSONToTable( string json, boolean ignoreConversions )
Converts the json into a table like util.JSONToTable
This version is noticably faster than Gmod's version and uses less memory in the process.
string util.FancyTableToJSON( table tbl, boolean pretty, boolean ignorecycle = false )
It's util.TableToJSON but faster and it will turn numbers into integers if they fit as one. This implementation will include null for values it cannot handle.
Gmod hides null but we don't meaning if for example we get {math.huge} as input, it will return [null] which still is valid json.