Lua Environment
Last updated
Last updated
Planetary Processing's server-side Lua environment runs using , this means it is effectively the same as Lua 5.1 but with some tweaks and significantly improved performance.
Please note that some of Lua and LuaJIT's libraries are not available within the PP environment. The following libaries are not available: os
, io
, jit
, table
, package
and coroutine
.
The math
library remains, as do various libraries added by PP. Additionally, require
, dofile
and similar will still work for loading Lua files from within your game repository.
Runtime metatables and metamethods are not currently supported.
Additionally, we have incorporated an open source JSON encoding/decoding library, documentation here:
On our backend, we implement tables in a slightly different way to the normal Lua virtual machine. Tables used as a standard dictionary are similar to regular Lua, however, non-serialisable objects (i.e. functions, etc.) are not guaranteed to be persisted.
Array-style tables (e.g. {1, 2, 3}
) are handled differently and as such we have provided a library for manipulating them that provides some of the functionality in Lua's table
library.
The library works by taking an array-style table, manipulating it, and returning the result. This is distinct from Lua's built in tables, as the modifications are not made in place.
We provide three functions: api.table.Append(table, item)
, api.table.Remove(table, index)
and api.table.Join(table, table)
.
Note that Append
can be used with multiple item parameters like so:
Note that modifying tables in-place by index is still supported as normal, and length operations will work as normal. However, you cannot index outside of the current length of the table.
We provide utilities through the api.util
section of the API.
The Unix timestamps used in time functions will provide the amount of time elapsed since: 00:00:00 1st January 1970
. Since this is a large integer, it will display in logs using scientific e notation. For example 1.741084186e+09
will be printed for a functional value of 1741083281
seconds.
Premium Only
These requests are rate limited to a maximum of 5 HTTP calls per update tick. The API is as follows:
Where the url and body are strings and the headers are a table of the form:
Every HTTP API endpoint returns the status code and the body of the response, as a string. Currently this process is sequential and blocking, so the code will not progress until there is a return.
An example of an HTTP Get request is below:
The global environment API is shown below, these functions are accessed by interfacing with the api.table
, api.util
, and api.http
objects from any server-side script.
These functions are accessed by interfacing with the api.table
object.
These functions are accessed by interfacing with the api.util
object.
These functions are accessed by interfacing with the api.http
object.
[This feature is still in Open Beta and may have some bugs. Please direct any feedback to the Planetary Processing Team on ]
We provide a simple HTTP API through the api.http
section of the API. This API is for making HTTP Requests from within your game. For external requests to your game please use our .
None
int
Returns the number of seconds elapsed since a fixed point in history (Unix epoch)
None
int
Returns the number of milliseconds elapsed since a fixed point in history (Unix epoch)
url: string
headers: table
code: int
body: string
Sends a GET request to an HTTP endpoint.
url: string
headers: table
body: string
code: int
body: string
Sends a POST request to an HTTP endpoint.
url: string
headers: table
body: string
code: int
body: string
Sends a PUT request to an HTTP endpoint.
url: string
headers: table
code: int
body: string
Sends a DELETE request to an HTTP endpoint.
table: table
item: Any
table
modified
Adds the item to the end of the table.
table: table
index: integer
table
modified
Removes an item from the table at the selected index.
table: table
table: table
table
modified
Combine one table with another, to form a single table.