feat: multi-package loading with base framework support

- Add RuntimeOptions.basePackages for loading framework packages before game package
- Add ScriptEngine.loadPackages() for multi-package module merging
- LuaDardoScriptEngine merges modules from all packages, game overrides framework
- PackageActivationController loads base packages first, then game package
- GamePackageManifest parses optional 'base' field
- Update docs: README, quick-start, lua-package-format, architecture
- Update all test mocks with loadPackages() implementation
This commit is contained in:
gem
2026-06-10 00:04:00 +08:00
parent 0d4fbd030c
commit 8ddc3be3a7
13 changed files with 255 additions and 7 deletions

View File

@@ -98,3 +98,77 @@ flutter run --dart-define=LUA_GAME_ID=flight
}
}
```
## Multi-package loading (base + game)
When multiple games share common modules (event router, diff utilities, panel stack, network layer), extract them into a framework package and load it before the game package.
Framework package structure:
```text
assets/games/_framework/
manifest.json
scripts/
app.lua
diff.lua
event_router.lua
ids.lua
net.lua
panel_stack.lua
```
Framework manifest:
```json
{
"gameId": "_framework",
"name": "Lua Game Framework",
"version": "1.0.0",
"runtimeApiVersion": 1,
"entry": "scripts/app.lua",
"assetsBase": "assets",
"modules": {
"app": "scripts/app.lua",
"diff": "scripts/diff.lua",
"event_router": "scripts/event_router.lua",
"ids": "scripts/ids.lua",
"net": "scripts/net.lua",
"panel_stack": "scripts/panel_stack.lua"
}
}
```
Game manifest (no framework modules needed):
```json
{
"gameId": "ludo",
"base": "_framework",
"modules": {
"state": "scripts/state.lua",
"rules": "scripts/rules.lua",
"main": "scripts/main.lua"
}
}
```
Game code imports framework modules transparently:
```lua
local app = runtime.import("app") -- from framework
local state = runtime.import("state") -- from game
```
Embed with base packages:
```dart
LuaGameWidget(
gameId: 'ludo',
runtimeOptions: const RuntimeOptions(
runtimeLuaRoot: 'packages/flame_lua_runtime/assets/runtime/lua',
basePackages: ['_framework'],
),
)
```
Module resolution order: game package modules override framework modules with the same name. The entry script always comes from the last package (game package).