aboutsummaryrefslogtreecommitdiffstats
path: root/prototypes/connections/pure-run.c
diff options
context:
space:
mode:
authoreunhhu <[email protected]>2026-09-26 17:55:14 +0100
committereunhhu <[email protected]>2026-09-26 17:55:14 +0100
commitef7ac7332f330fddc2de6194f926e0c0a84ca2b4 (patch)
treeb7e1764c6ffcbe6f2d7c64ead1b91b352e3b7b0a /prototypes/connections/pure-run.c
parentae48b510c9eec3e47ea551b4c4cad640d13310cd (diff)
downloadpure-ef7ac7332f330fddc2de6194f926e0c0a84ca2b4.tar.gz
pure-ef7ac7332f330fddc2de6194f926e0c0a84ca2b4.zip
Add time: timers, now, floor and a floored modulo
An input may be a timer (kind 4, its period of 1 ms to a day in place of a key name): pure_app_tick delivers a tick, an event saved like a key's. NOW gives handlers the time the host set in PureApp.now (milliseconds since 1970, UTC), so a script replays any time and views stay functions of state; FLOOR and MOD take times apart, MOD taking the divisor's sign as floor division leaves it, a zero too. pure-run gains time MS and tick NAME.
Diffstat (limited to 'prototypes/connections/pure-run.c')
-rw-r--r--prototypes/connections/pure-run.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/prototypes/connections/pure-run.c b/prototypes/connections/pure-run.c
index d97d277..ef36965 100644
--- a/prototypes/connections/pure-run.c
+++ b/prototypes/connections/pure-run.c
@@ -10,11 +10,12 @@
* states live in that tree store: it starts from them, and frame changes are
* saved at the end of input or by save. --batch N defers saving and saves
* every N commands (and at the end), so N events share one commit.
- * down NAME | up NAME | frame [N] | type NAME HEX|- | replace PATH | save | show
+ * down NAME | up NAME | frame [N] | type NAME HEX|- | tick NAME | time MS | replace PATH | save | show
* Text states and text views print as JSON strings; cursors as byte positions;
* lists as arrays of objects; indices as positions; a table view as an array
* with an object of its columns per row. A failed view or cell is null. */
static const char *const fault_names[] = {"none", "divide", "non_finite", "clamp", "limit", "not_found", "encoding", "exists"};
+/* time MS sets the time events see (milliseconds since 1970); tick NAME is a timer's tick. */
static bool load(const char *path, PureModule *module) {
FILE *file = fopen(path, "rb");
@@ -169,6 +170,15 @@ int main(int argc, char **argv) {
text[i] = (unsigned char)(hex(data[2 * i]) << 4 | hex(data[2 * i + 1]));
if (input < 0) failure = "unknown input";
else if (pure_app_text(&app, (uint32_t)input, (PureSpan){text, length}) != PURE_OK) failure = "event failed";
+ } else if (!strcmp(command, "tick")) {
+ int input = pure_module_input(app.module, argument);
+ if (input < 0) failure = "unknown input";
+ else if (pure_app_tick(&app, (uint32_t)input) != PURE_OK) failure = "event failed";
+ } else if (!strcmp(command, "time")) {
+ char *end;
+ double now = strtod(argument, &end);
+ if (!*argument || *end || !(now >= 0 && now < 1e15)) failure = "time";
+ else app.now = now;
} else if (!strcmp(command, "frame")) {
long count = *argument ? strtol(argument, NULL, 10) : 1;
if (count < 1 || count > 600) failure = "frame count";