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

View File

@@ -39,6 +39,11 @@ pico_sdk_init()
# Add executable. Default name is the project name, version 0.1
# Collect Lua source files
file(GLOB LUA_SOURCES
"${CMAKE_CURRENT_LIST_DIR}/lib/lua/*.c"
)
add_executable(basic1
basic1.cpp
lib/input_manager.cpp
@@ -47,6 +52,9 @@ add_executable(basic1
games/demo_game.cpp
games/monopoly/monopoly_game.cpp
games/monopoly/player.c
games/lua_game.cpp
games/lua_bindings.cpp
games/lua_game_loader.cpp
lib/st7796/st7796.c
lib/ft6336u/ft6336u.c
lib/sd_card/sd_card.c
@@ -65,11 +73,18 @@ add_executable(basic1
lib/fatfs/source/ffunicode.c
lib/Pico_ePaper_Code/c/lib/Config/DEV_Config.c
lib/Pico_ePaper_Code/c/lib/e-Paper/EPD_4in2_V2.c
${LUA_SOURCES}
)
pico_set_program_name(basic1 "basic1")
pico_set_program_version(basic1 "0.1")
# Add compile definitions early (before headers are parsed)
target_compile_definitions(basic1 PRIVATE
PICO_BOARD_ADAFRUIT_FEATHER_RP2350=1
LUA_32BITS # Use 32-bit integers for Lua on embedded
)
# Modify the below lines to enable/disable output over UART/USB
pico_enable_stdio_uart(basic1 0)
pico_enable_stdio_usb(basic1 1)
@@ -84,6 +99,7 @@ target_include_directories(basic1 PRIVATE
${CMAKE_CURRENT_LIST_DIR}/games
${CMAKE_CURRENT_LIST_DIR}/games/monopoly
${CMAKE_CURRENT_LIST_DIR}/lib
${CMAKE_CURRENT_LIST_DIR}/lib/lua
${CMAKE_CURRENT_LIST_DIR}/lib/fatfs/source
${CMAKE_CURRENT_LIST_DIR}/lib/st7796
${CMAKE_CURRENT_LIST_DIR}/lib/ft6336u
@@ -106,8 +122,3 @@ pico_add_extra_outputs(basic1)
# RP2350-specific: Set the boot stage2 and ensure proper image definition
# This is critical for reliable cold boot on RP2350
pico_set_binary_type(basic1 default)
# Add binary info for proper RP2350 boot
target_compile_definitions(basic1 PRIVATE
PICO_BOARD_ADAFRUIT_FEATHER_RP2350=1
)