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>
31 lines
1.1 KiB
C++
31 lines
1.1 KiB
C++
#pragma once
|
|
|
|
#include <cstddef>
|
|
|
|
namespace kvida {
|
|
|
|
// Mounts storage and loads the script from there (see
|
|
// components/drivers/include/storage.h), falling back to the compiled-in
|
|
// default (src/default_script.h) if none is stored yet. The script only
|
|
// *defines* the on_tick() function -- call lua_runtime_tick() to actually
|
|
// run it. Call once at boot.
|
|
void lua_runtime_init();
|
|
|
|
// Calls the script's on_tick() global function -- one "wake, execute
|
|
// Lua, publish changes, sleep" cycle, per AGENTS.md's power philosophy.
|
|
// A Lua runtime error is logged, not fatal: a script bug shouldn't take
|
|
// down the device.
|
|
void lua_runtime_tick();
|
|
|
|
// Persists `script` to storage and hot-reloads it into a fresh Lua
|
|
// state, replacing whatever's currently running -- no reboot needed.
|
|
// Wired to transport::set_script_change_handler() by main.cpp.
|
|
void lua_runtime_reload(const char *script, size_t len);
|
|
|
|
// Copies the currently-running script into buf (capacity cap), returns
|
|
// the number of bytes written. Wired to transport::set_script_provider()
|
|
// by main.cpp.
|
|
size_t lua_runtime_current_script(char *buf, size_t cap);
|
|
|
|
} // namespace kvida
|