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

@@ -64,6 +64,53 @@ runtime:*.lua
`runtime:` paths must not contain `/`, `..`, or an empty filename.
## Base packages
A game manifest can declare a `base` field to indicate it depends on a framework package:
```json
{
"gameId": "ludo",
"base": "_framework",
"modules": { ... }
}
```
The `base` field is metadata. Actual loading is controlled by `RuntimeOptions.basePackages`:
```dart
LuaGameWidget(
gameId: 'ludo',
runtimeOptions: const RuntimeOptions(
basePackages: ['_framework'],
),
)
```
Loading order:
1. Base packages are loaded first, in `basePackages` order.
2. The game package is loaded last.
3. All modules are merged into a flat map.
4. Later packages override earlier packages on name collision.
5. The entry script always comes from the last (game) package.
This means a game can override any framework module by declaring a module with the same name in its own manifest.
## Multi-package module resolution
When Lua code calls `runtime.import("xxx")`:
1. Look up `xxx` in the merged module map (game modules first, then framework).
2. If not found, throw `FormatException: Lua module is not declared in manifest.modules`.
Framework modules are transparent to game code:
```lua
local app = runtime.import("app") -- resolved from framework
local state = runtime.import("state") -- resolved from game
```
## Entry module
The manifest `entry` module should expose lifecycle/event functions expected by the script engine. Keep game-specific state in Lua modules and return runtime diffs/commands through the approved protocol.