Resource data storage
Resource data storage
Server-side; since 0.1.4.
Three resource-scoped persistence functions support map saves and Lua exports. They do not expose arbitrary filesystem paths or MySQL connections.
| Function | Return | File in the calling resource |
|---|---|---|
readResourceData(key) |
JSON text string, or false for missing/invalid/unreadable data | .storage/data-KEY.json
|
writeResourceData(key, json) |
boolean success; json must be a nonempty valid JSON string | .storage/data-KEY.json
|
writeResourceText(key, text) |
boolean success; writes nonempty text without validating/executing Lua | .storage/data-KEY.lua
|
Keys contain 1-64 ASCII letters, digits, underscores or hyphens. Pass a key only, not a path, prefix data- or extension. Each resource can access only its own storage root. readResourceData reads JSON only; it does not read a writeResourceText Lua export. No matching generic Lua-text read function is exposed here.
Example
local json = toJSON({format="my-layout", version=1, objects={}})
if json and writeResourceData("layout", json) then
outputDebugString("Layout saved")
else
outputDebugString("Layout save failed", 1)
end
local saved = readResourceData("layout")
local layout = saved and fromJSON(saved)
-- Validate your own schema before using layout; JSON validity is not a schema check.
local exported = writeResourceText("layout_export", "MapScene = {}\n")
-- This only writes text. It neither starts a resource nor executes that text.
Safety and limits
Maximum payload size: 1048576 bytes (1 MiB) per file. Before writing, the current storage directory is checked: a write is refused if existing regular files already total more than 64 MiB or their count exceeds 512; backups/temp files also count. These are pre-write admission checks, not a reservation of space for the incoming file and backup. Filesystem errors can also cause false. The map editor adds a stricter 1000000-byte transfer limit.
Writes use a temporary file and replacement, retaining one .bak copy when overwriting an existing destination. Keep independent backups; this is not a database transaction across multiple keys or an unlimited revision archive. Path traversal and symlink/junction escapes are rejected. Never accept untrusted client text as executable exported Lua; writeResourceText does not validate its content for you.
The functions validate storage/JSON, not gameplay permissions: server scripts must authorize who may submit data, validate schema and bound request sizes/rates. The editor implements those checks and a named-map session lock. See Map editor for its filenames and Map scene deployment for the explicit publication step.