Add Lua 5.4 scripting integration for dynamic game loading

- Integrated Lua 5.4 engine (32-bit mode for embedded ARM)
- Created LuaGame wrapper class implementing Game interface
- Added C++ bindings exposing renderer, game state, and input to Lua
- Implemented SD card loader for automatic .lua game discovery
- Updated GameLauncher to support std::function for lambda captures
- Made Game class members public for Lua bindings access
- Added example Lua games: counter, snake, bouncing ball
- Included comprehensive API documentation

Games can now be written as .lua text files on SD card and loaded
without recompilation. Build size: 747KB UF2, Lua VM uses ~50-80KB RAM.
This commit is contained in:
Adolfo Reyna
2026-02-07 11:56:03 -05:00
parent c8af4f6638
commit e6e4eca188
74 changed files with 29098 additions and 13 deletions

40
games/lua_game_loader.h Normal file
View File

@@ -0,0 +1,40 @@
// ============================================================================
// LUA GAME LOADER - HEADER
// ============================================================================
// Scans SD card for .lua game scripts and registers them with GameLauncher
#ifndef LUA_GAME_LOADER_H
#define LUA_GAME_LOADER_H
#include "../lib/game_launcher.h"
/**
* @brief Lua Game Loader - discovers and registers Lua games from SD card
*/
class LuaGameLoader {
public:
/**
* @brief Scan SD card /games directory and register all .lua files
* @param launcher GameLauncher to register games with
* @return Number of Lua games found and registered
*/
static int register_all_games(GameLauncher* launcher);
private:
/**
* @brief Parse metadata from Lua script comments
* @param script_path Path to .lua file
* @param name Output: game name (default: filename)
* @param description Output: game description (default: empty)
* @return true if file could be read
*/
static bool parse_metadata(const char* script_path, char* name, char* description);
/**
* @brief Factory function for creating LuaGame instances
*/
static Game* create_lua_game(const char* script_path, uint16_t width, uint16_t height,
LowLevelRenderer* renderer, LowLevelGUI* gui, InputManager* input_manager);
};
#endif // LUA_GAME_LOADER_H