API/serialization: Difference between revisions
Jump to navigation
Jump to search
imported>OCDoc Import Imported from legacy OpenComputers documentation at ocdoc.cil.li |
Clean up Markdown artifacts from DokuWiki migration |
||
| Line 3: | Line 3: | ||
This module provides simple value serialization. | This module provides simple value serialization. | ||
* | * <code>serialization.serialize(value: any except functions[, pretty:boolean/number]): string</code> | ||
<pre>Generates a string from an object that can be parsed again using | <pre>Generates a string from an object that can be parsed again using serialization.unserialize. The generated output is Lua code. Supports basic types (nil, boolean, number, string) and tables without cycles (will error out when cycles are detected, unless in pretty print mode). Properly handles NaN values and infinity. | ||
The | The pretty mode can be used to generate output for display to the user, this output will in most circumstances not be readable with serialization.unserialize. | ||
The value of pretty defines the number of entries that will be printed. | The value of pretty defines the number of entries that will be printed. | ||
If pretty is set to true it will by default print 10 entries. | If pretty is set to true it will by default print 10 entries. | ||
This function can be useful for sending messages via a network card. | This function can be useful for sending messages via a network card. | ||
</pre> | </pre> | ||
* | * <code>serialization.unserialize(value: string): any</code> | ||
<pre>Restores an object previously saved with | <pre>Restores an object previously saved with serialization.serialize. | ||
</pre> | </pre> | ||
== Contents == | == Contents == | ||
{{:API/contents}} | {{:API/contents}} | ||
Latest revision as of 20:26, 24 August 2026
Serialization API
This module provides simple value serialization.
serialization.serialize(value: any except functions[, pretty:boolean/number]): string
Generates a string from an object that can be parsed again using serialization.unserialize. The generated output is Lua code. Supports basic types (nil, boolean, number, string) and tables without cycles (will error out when cycles are detected, unless in pretty print mode). Properly handles NaN values and infinity. The pretty mode can be used to generate output for display to the user, this output will in most circumstances not be readable with serialization.unserialize. The value of pretty defines the number of entries that will be printed. If pretty is set to true it will by default print 10 entries. This function can be useful for sending messages via a network card.
serialization.unserialize(value: string): any
Restores an object previously saved with serialization.serialize.
Contents
| APIs | |
|---|---|
| OpenOS | buffer - colors - component - computer - event - filesystem - uuid - internet - keyboard - note - process - rc - robot - serialization - shell - sides - term - text - thread - transforms - unicode |
| Lua Libraries | coroutine - package - io - os |