Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions plugins/superstack/skills/s2-lua/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ Superstack. These facts shape all code:

- **Code is a bundle.** `main.lua` is the entry point. Other `.lua` files in
the bundle load with `require("name")`, which runs `name.lua` and returns
its first value. `require` has no cache, so it runs the file again on every
call. Code files are read-only.
its first value. A file runs once, and later calls return the same value.
Code files are read-only.
- Standard libraries: basic, `math`, `string`, `table`, `utf8`, `coroutine`,
plus a built-in `json` with `json.encode` and `json.decode`. **There is no
`io`, `os`, `debug` or `package`.** Use `storage.*`, `time.*` and `device.*`
Expand Down Expand Up @@ -112,9 +112,8 @@ in [references/footguns.md](references/footguns.md).
one crashes the program.
10. **Temporary files die with the run**: `storage.open()` returns a handle to
a new temporary file, deleted on close and whenever the code starts,
stops, crashes or is replaced. `handle:read()` with no options returns
**line 1 only**. Nothing on the device survives a restart, so keep durable
state on the user's server.
stops, crashes or is replaced. Nothing on the device survives a restart,
so keep durable state on the user's server.
11. **Power**: ports boot **live at 1.8 V**, so a 3.3 V sensor on an
unconfigured port half-works rather than failing cleanly. Call
`device.power.set_vout(3.3)` in setup. It sets **all** ports at once (1.8 to
Expand Down
13 changes: 7 additions & 6 deletions plugins/superstack/skills/s2-lua/references/footguns.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,11 @@ named files.

- `handle:write(data)` replaces the contents. `handle:append(data)` adds to
them.
- `handle:read()` with no options returns **line 1 only**. Use
- `handle:read()` with no options returns the whole file, and raises
`not enough memory` when the file does not fit in free memory. Use
`handle:read{ line = n }` for line `n` (negative counts from the end), or
`handle:read{ length = n, offset = o }` for bytes.
`handle:read{ length = n, offset = o }` for bytes, which also reads a large
file in parts.
- `handle:close()` deletes the file.
- **Every temporary file is deleted when the code starts, stops, restarts or
crashes, when new code arrives, and at reboot.** Nothing survives the run
Expand All @@ -241,9 +243,9 @@ named files.
`there is not enough storage`.

Code files in the bundle are read-only. Load one with `require("name")`, which
runs `name.lua` and returns its first value. `require` has no cache and runs
the file again on every call, and the name is a path: `require("lib/sensor")`
loads `lib/sensor.lua`.
runs `name.lua` once and returns its first value, and later calls return the
same value. The name is a path: `require("lib/sensor")` loads
`lib/sensor.lua`.

## Retry pattern for a dropped connection

Expand Down Expand Up @@ -364,5 +366,4 @@ Checked against firmware 3.0.0:
| SPI | Pin options `sclk_pin`, `mosi_pin`, `miso_pin` and `cs_pin` are all or none. At most 8191 bytes per transfer |
| Digital input | `get_input` and `assign_input_event` pull **down** unless `pull` says otherwise. `set_output` needs a boolean, not `1` or `0` |
| PSM timing | Requested as a 900 s periodic update and 30 s active time, hence "up to 15 minutes". The network may grant different values |
| `get_time_date().yearday` | 0-based: January 1 is 0 |
| State across new code | Globals do not survive. Code starts from the top of `main.lua`, and temporary files are gone |
Loading