Module Coding
En-/Decodes to/from various formats.
You can require all sub-modules at once by requiring "!all".
Module Status: Experimental 2020-10-31.
Usage:
local Coding = require('__eradicators-library__/erlib/lua/Coding/!init')()
Hydra
HydraOptions | Hydra implements some new options that are not in serpent. |
Hydra.lines(object, options) | Multi-line serialization preset. |
Hydra.line() | Single-line serialization preset. |
Hydra.block() | Pretty printable serialization preset. |
Hydra.dump() | Raw serialize with recursive tables preset. |
Hydra.load() | Deserialization. |
Hydra.serialize() | Raw serpent. |
Hydra.encode() | Alias of Hydra.dump |
Hydra.decode(data) | Similar to Hydra.load, but only has one return value. |
Bluestring
Bluestring.encode(data[, serializer='json'[, prefix='0']]) | |
Bluestring.decode(data[, deserializer='json'[, prefix='0']]) |
Base64
Base64.encode(data) | |
Base64.decode(data) |
Json
Json.encode(data) | |
Json.decode(data) |
Zip
Zip.encode(data) | |
Zip.decode(data) |
Crc32
Crc32.encode(data) |
Sha256
Sha256.encode(data) |
Hydra
See the official repository for detailed usage instructions.
This is a customized version of "serpent" - renamed to avoid confusion with Factorios built-in serpent installation. This page only documents changes compared to serpent.
Equal to Factorios built-in serpent, Hydra represents redundant sub-tables references by the number 0 zero (instead of nil like normal serpent does).
Hydra knows about factorio userdata like LuaEntity, LuaPlayer, etc..
Usage:
local Hydra = require('__eradicators-library__/erlib/lua/Coding/Hydra')()
- HydraOptions
-
Hydra implements some new options that are not in serpent. These work for
all presets but are off by default, except for Hydra.lines, where they are on.
Fields:
- indentlevel NaturalNumber, limits indentation of very deep sub-tables.
- showref boolean, adds a comment to the output of self-referencing sub-tables.
- Hydra.lines(object, options)
-
Multi-line serialization preset. A more readable, more informative alternative to
Hydra.block(). Defaults to indentlevel = 1, showref = true, nocode = true.
Parameters:
- object AnyValue
- options HydraOptions
Usage:
local t = {'a','b','c'}; t = {t,{t,t},{t,t,t},[42]={{{{{table.insert}}}}}} local opts={indentlevel=1,showref=true,nocode=true} --"lines" mode default print(Hydra.lines(t,opts)) > { > {"a", "b", "c"}, > {0 --[[ self[1] ]], 0 --[[ self[1] ]]}, --self-ref comment > {0 --[[ self[1] ]], 0 --[[ self[1] ]], 0 --[[ self[1] ]]}, --one level indented > [42] = {{{{{function()end}}}}} --short code skip > }
print(Hydra.lines{game, game.player, game.player.force}) > { > {__self = "LuaGameScript"}, > {__self = "LuaPlayer"}, > {__self = "LuaForce"} > }
- Hydra.line()
- Single-line serialization preset.
- Hydra.block()
- Pretty printable serialization preset.
- Hydra.dump()
- Raw serialize with recursive tables preset.
- Hydra.load()
- Deserialization.
- Hydra.serialize()
- Raw serpent.
- Hydra.encode()
- Alias of Hydra.dump
- Hydra.decode(data)
-
Similar to Hydra.load, but only has one return value.
Parameters:
- data string a serialized table
Returns:
Bluestring
See blueprint string format on the wiki for further information.
Note: serpent serialization is only for json-incompatible mod data. The resulting string will not be blueprint comatible.
Note: uses LuaGameScript.encode_string and LuaGameScript.decode_string and LuaGameScript.table_to_json and LuaGameScript.json_to_table when available and native lua otherwise.
Usage:
local Bluestring = require('__eradicators-library__/erlib/lua/Coding/Bluestring')()
- Bluestring.encode(data[, serializer='json'[, prefix='0']])
-
Parameters:
- data table or string Tables will be serialized to strings before compression.
- serializer string or nil , 'json' or 'serpent'. (default 'json')
- prefix string , the version marker byte (default '0')
Returns:
Usage:
LuaItemStack.import_stack(Bluestring.encode(my_bp_table))
- Bluestring.decode(data[, deserializer='json'[, prefix='0']])
-
Parameters:
- data string an encoded string
- deserializer string, nil or false , 'json' or 'serpent'. If set to false the data is decompressed but not deserialized. (default 'json')
- prefix string , the version marker byte (default '0')
Returns:
Usage:
local my_bp_table = Bluestring.decode(LuaItemStack.export_stack())
Base64
Usage:
local Base64 = require('__eradicators-library__/erlib/lua/Coding/Base64')()
- Base64.encode(data)
-
Parameters:
- data string the original string
Returns:
-
string
the encoded string
- Base64.decode(data)
-
Parameters:
- data string encoded string
Returns:
-
string
the original string
Json
Usage:
local Json = require('__eradicators-library__/erlib/lua/Coding/Json')()
- Json.encode(data)
-
Parameters:
- data string the original string
Returns:
-
string
the encoded string
- Json.decode(data)
-
Parameters:
- data string the encoded string
Returns:
-
string
the original string
Zip
Usage:
local Zip = require('__eradicators-library__/erlib/lua/Coding/Zip')()
- Zip.encode(data)
-
Parameters:
- data string the original string
Returns:
-
string
the compressed string
- Zip.decode(data)
-
Parameters:
- data string the compressed string
Returns:
-
string
the original string
Crc32
Usage:
local Crc32 = require('__eradicators-library__/erlib/lua/Coding/Crc32')()
- Crc32.encode(data)
-
Parameters:
- data string the original string
Returns:
Sha256
Usage:
local Sha256 = require('__eradicators-library__/erlib/lua/Coding/Sha256')() oding.Sha256 = (_ENV.bit32) and import 'erlib/lua/Coding/Sha256' or nil