lua-integration

Implement and troubleshoot Lua script execution in Megahub ESP32 firmware.

5|2|Updated Dec 26, 2025
One-click install
npx skills add https://github.com/mirkosertic/Megahub --skill lua-integration
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: lua-integration
Source: https://github.com/mirkosertic/Megahub/tree/main/.claude/skills/lua-integration
Command: npx skills add https://github.com/mirkosertic/Megahub --skill lua-integration

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps you implement, debug, and harden Lua scripting inside Megahub so ESP32 firmware can run user scripts reliably without breaking device control or memory stability.

Core Features & Use Cases

  • Lua runtime integration: Understand how Megahub creates a Lua 5.4 state, loads libraries, and executes scripts through the firmware entry points.
  • Custom bindings and APIs: Work with the Megahub Lua bridge, including hub.init and hub.startthread for initialization and coroutine-based background tasks.
  • Blockly to Lua pipeline: Trace how browser-generated Lua code is produced, transmitted over BLE, and executed on the device.
  • Safety and stability: Apply the required error handling, pcall usage, stack sizing, and heap-aware practices that keep the firmware responsive.
  • Use case: Update a Blockly-generated motor control flow so it launches a monitoring thread, handles Lua errors cleanly, and avoids starving other ESP32 tasks.

Quick Start

Use this Skill to trace how a Lua script moves from Blockly or BLE into Megahub firmware, then adjust the bindings, error handling, or thread settings needed for your change.

Frequently Asked Questions about lua-integration

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run Lua scripts safely on an ESP32 without crashing the firmware?

Safe Lua script execution on ESP32 requires lua_pcall for protected calls, custom error handlers, and heap-aware Lua state creation to prevent memory exhaustion and keep firmware responsive.

How does the Blockly to Lua pipeline work for BLE-triggered script execution?

The Blockly to Lua pipeline generates Lua code in the browser, transmits it over BLE to the ESP32, and executes it through Megahub firmware entry points using safe Lua runtime integration.

Can I create background threads in Lua on ESP32 using coroutines?

Yes, you can create coroutine-based background threads using Megahub custom bindings like hub.startthread, while sizing FreeRTOS tasks correctly to avoid starving other ESP32 processes.

What is the best way to handle Lua script errors in Megahub firmware?

The best way to handle Lua errors in Megahub firmware is using pcall within the Lua 5.4 state alongside custom error handlers, catching exceptions cleanly without breaking device control.

Do I need FreeRTOS task sizing when integrating Lua bindings on ESP32?

Yes, FreeRTOS task sizing is required when integrating Lua bindings on ESP32 to ensure heap-aware Lua state creation and proper stack sizing keep the firmware responsive during script execution.

Why does my ESP32 freeze when running a Blockly-generated Lua motor control flow?

Your ESP32 freezes because the Lua motor control flow lacks proper pcall error handling and FreeRTOS task sizing, causing background monitoring threads to starve other critical device processes.