Files
kvida-os/components/lua_runtime/include/lua_runtime.h
Ronny Eia eae6d3af5a Add Lua runtime: chip temp -> LED color -> HA, verified live
Sandboxed Lua state (espressif/lua v5.5.0, base/table/string/math only,
no io/os/package/debug) exposes a kvida API table (chip_temperature,
set_led, publish) to a compiled-in default script that reads chip
temperature, maps it to an LED color, and publishes the reading to
Home Assistant. Generalizes transport's publish_chip_temperature()
into publish_value(name, value), the first real use of AGENTS.md's
semantic publish API. Requires -DLUA_32BITS globally since this
toolchain's long long support isn't visible to Lua's default build.

Verified on real ESP32-C6 hardware: no crashes/errors across multiple
serial monitor windows, LED changes color, chip_temperature sensor
appears in Home Assistant via MQTT Discovery.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
2026-07-12 09:17:06 +02:00

18 lines
558 B
C++

#pragma once
namespace kvida {
// Creates the sandboxed Lua state and loads the default script (see
// src/default_script.h). 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();
} // namespace kvida