Add flexible module loading and complete file embedding

- Support any folder structure (no hard-coded folders)
 - Embed all file types recursively from any folder
 - Fix require() dot-to-slash conversion for embedded modules
 - Clean build folder for fresh builds every time
 - Generate empty headers for Lua-only projects

 Backward compatible with existing projects.
This commit is contained in:
2025-11-10 01:58:00 +05:30
parent 8c9367f368
commit d9d1a8a51e
9 changed files with 283 additions and 206 deletions

View File

@@ -24,21 +24,48 @@ if errorlevel 1 (
exit /b 1
)
REM ALWAYS clean build folder for fresh build
echo Cleaning build directory for fresh build...
del /Q /S * >nul 2>&1
for /d %%p in (*) do rmdir "%%p" /s /q >nul 2>&1
echo * Build directory cleaned
echo.
REM Clean old embedded files
echo Cleaning old embedded files...
echo Ready for fresh build...
del /Q embedded_main.h embedded_assets.h 2>nul
REM Check for Lua files
REM Auto-copy from game folder if it exists
echo.
if exist "..\game" (
echo Found game/ folder - auto-copying ALL contents to build...
REM Copy all files from game folder recursively, excluding LSP files
xcopy /E /I /Y /EXCLUDE:..\game\ReiLua_API.lua+..\game\.luarc.json "..\game\*" . >nul 2>&1
if exist "..\game\ReiLua_API.lua" del /Q "ReiLua_API.lua" 2>nul
if exist "..\game\.luarc.json" del /Q ".luarc.json" 2>nul
echo * Copied ALL game files and folders
echo * All folder structures preserved ^(user-created folders included^)
echo.
)
REM Check for Lua files
echo Checking for Lua files...
dir /b *.lua >nul 2>&1
if errorlevel 1 (
echo.
echo WARNING: No Lua files found in build directory!
echo.
echo Please copy your Lua files:
echo cd build
echo copy ..\your_game\*.lua .
if exist "..\game" (
echo No Lua files found in game/ folder.
echo Add your main.lua to game/ folder and try again.
) else (
echo Tip: Create a game/ folder in project root and add main.lua there.
echo Or manually copy files:
echo cd build
echo copy ..\your_game\*.lua .
)
echo.
set /p CONTINUE="Do you want to continue anyway? (y/N): "
if /i not "%CONTINUE%"=="y" exit /b 1
@@ -47,24 +74,22 @@ if errorlevel 1 (
dir /b *.lua
)
REM Check for assets folder
REM Check for non-Lua data files (any folder, any file type)
echo.
echo Checking for assets...
if not exist "assets" (
echo.
echo WARNING: No assets folder found!
echo.
echo To embed assets, create the folder and copy files:
echo cd build
echo mkdir assets
echo copy ..\your_game\assets\* assets\
echo.
set /p CONTINUE="Do you want to continue without assets? (y/N): "
if /i not "%CONTINUE%"=="y" exit /b 1
set EMBED_ASSETS=OFF
) else (
echo Found assets folder
echo Checking for data files to embed...
set DATA_COUNT=0
for /r %%f in (*) do (
echo %%~nxf | findstr /i /v ".lua .exe .o .a CMake Makefile" >nul
if not errorlevel 1 set /a DATA_COUNT+=1
)
if %DATA_COUNT% GTR 0 (
echo Found data files to embed
echo ^(includes: images, sounds, config, data, and any other files^)
set EMBED_ASSETS=ON
) else (
echo No non-Lua files found ^(only Lua code will be embedded^)
set EMBED_ASSETS=OFF
)
echo.
@@ -72,7 +97,7 @@ echo ================================
echo Build Configuration
echo ================================
echo Lua Embedding: ON
echo Asset Embedding: %EMBED_ASSETS%
echo Data Embedding: %EMBED_ASSETS%
echo Build Type: Release
echo ================================
echo.