aboutsummaryrefslogtreecommitdiff
path: root/util/travis
diff options
context:
space:
mode:
authorWuzzy <almikes@aol.com>2017-05-21 19:57:22 +0000
committerLoic Blot <loic.blot@unix-experience.fr>2017-06-03 20:06:25 +0200
commit956892c226d2223e1cdfe9a8f7fe985af672aee9 (patch)
tree4cd13ce99fcfda88a6c7c8d9d80ff807f0ae2feb /util/travis
parentf2e78f31ab8049da9183d344aa3e8e23a25d999a (diff)
Translated using Weblate (German)
Currently translated at 99.8% (1022 of 1024 strings)
Diffstat (limited to 'util/travis')
0 files changed, 0 insertions, 0 deletions
ef='#n98'>98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
# serialize_lib API

## Serialization Library (serialize.lua)

### config table

Serialization functions accept a config table. Currently only one configuration option is defined.

    config = {
        	skip_empty_tables = false
        	-- used for write_to_fd/write_to_file
        	-- if true, does not store empty tables
        	-- On next read, keys that mapped to empty tables resolve to nil
    }

If you want to use all-default config options, you can pass `nil` as the config parameter.

### Serialization limits

  * Only strings, booleans, numbers and tables can be serialized, no functions or userdata
  * serialize_lib requires that no reference loops are present in the table to be serialized. Currently, when passing a table that has a reference loop, serialize_lib will produce a stack overflow.

### Functions

All of these functions call `error(<message>)` if an error occurs. Errors can be caught with `pcall()`.

#### write_to_fd(root_table, file, config)
Writes the contents of `root_table` to the file from the file handle given by `file`, and closes the file descriptor afterwards.

#### write_to_file(root_table, filename, config)
First, opens `filename` for write. Then, writes the contents of `root_table` to the file.

#### read_from_fd(file)
Reads the file from the file handle given by `file`, and closes the file descriptor afterwards. Returns the deserialized table.

#### read_from_file(filename)
First, opens `filename` for read. Then, reads the file and returns the deserialized table.

### External Lua Module
serialize.lua can be loaded as a standard Lua module even outside Minetest, like this:

    local serialize = require("serialize")

## General API

### Minetest wrappers for serialization functions

Serialize_lib wraps write_to_file and read_from_file into 2 functions that do not throw errors but instead log the fact to the server log and have an appropriate return value:

#### serialize_lib.write_table_to_file(root_table, filename)

Serializes `root_table` into `filename`. On success, returns true. On failure, logs the error, then returns false and the error message.

#### serialize_lib.read_table_from_file(filename)