Add persistent script storage + hot-reload, verified live
lua_runtime now loads the running script from a new LittleFS-backed drivers::storage (joltwallet/littlefs, the project's fifth external managed component -- mounts the "storage" partition already reserved in partitions.csv), falling back to the compiled-in default script only on first boot. transport exposes GET/POST /api/script -- raw Lua text, not JSON, since json_helpers.h can't round-trip scripts safely -- relayed to lua_runtime via the same callback-registration pattern already used for LedColorHandler, keeping transport free of a dependency on lua_runtime. lua_runtime_reload() persists and hot-swaps to a fresh Lua state immediately, no reboot. Verified on real ESP32-C6 hardware: script loads via kvida-sdk, an edited script hot-reloads within one tick, and the edit survives a power cycle (proving LittleFS persistence, not just an in-RAM change). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace kvida {
|
||||
@@ -29,4 +30,17 @@ void publish_value(const char *name, double value);
|
||||
using LedColorHandler = void (*)(uint8_t red, uint8_t green, uint8_t blue);
|
||||
void set_led_color_handler(LedColorHandler handler);
|
||||
|
||||
// Same no-dependency-on-other-components pattern as LedColorHandler:
|
||||
// registered by main so a POST to /api/script can hand the new script to
|
||||
// `lua_runtime` without transport depending on it. `script` is not
|
||||
// NUL-terminated by the caller's guarantee -- handlers must use `len`.
|
||||
using ScriptChangeHandler = void (*)(const char *script, size_t len);
|
||||
void set_script_change_handler(ScriptChangeHandler handler);
|
||||
|
||||
// Registered by main so GET /api/script can pull the currently-running
|
||||
// script from `lua_runtime`. Called with a buffer of size `cap`; returns
|
||||
// the number of bytes written (0 if no provider is registered yet).
|
||||
using ScriptProvider = size_t (*)(char *buf, size_t cap);
|
||||
void set_script_provider(ScriptProvider provider);
|
||||
|
||||
} // namespace kvida
|
||||
|
||||
Reference in New Issue
Block a user