Add Lua debug logging API
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flame_lua_runtime/runtime/diagnostics/runtime_diagnostics.dart';
|
||||
import 'package:flame_lua_runtime/runtime/packages/game_package.dart';
|
||||
import 'package:flame_lua_runtime/runtime/packages/game_package_manifest.dart';
|
||||
import 'package:flame_lua_runtime/runtime/models/runtime_event.dart';
|
||||
@@ -895,6 +896,51 @@ end
|
||||
expect(c.y, 53);
|
||||
});
|
||||
|
||||
test('runtime.log records Lua debug messages in diagnostics', () async {
|
||||
final package = await _createPackage(
|
||||
mainScript: '''
|
||||
function smoke_test(ctx)
|
||||
runtime.log("smoke", ctx.runtimeApiVersion)
|
||||
return true
|
||||
end
|
||||
|
||||
function init(ctx)
|
||||
runtime.log("init", true, nil)
|
||||
return {}
|
||||
end
|
||||
|
||||
function on_event(event)
|
||||
runtime.log("event", event.type, event.target)
|
||||
return {}
|
||||
end
|
||||
''',
|
||||
);
|
||||
final diagnostics = RuntimeDiagnostics();
|
||||
final engine = LuaDardoScriptEngine(diagnostics: diagnostics);
|
||||
|
||||
await engine.loadPackage(package);
|
||||
expect(engine.smokeTest({'runtimeApiVersion': 1}), isTrue);
|
||||
engine.init({'runtimeApiVersion': 1});
|
||||
engine.dispatchEvent(
|
||||
const RuntimeEvent(
|
||||
type: RuntimeEventType.tap,
|
||||
target: 'debug_button',
|
||||
handler: 'debug',
|
||||
),
|
||||
);
|
||||
|
||||
expect(
|
||||
diagnostics.entries.map((entry) => entry.type),
|
||||
everyElement(RuntimeDiagnosticType.luaLog),
|
||||
);
|
||||
expect(diagnostics.entries.map((entry) => entry.message), [
|
||||
'smoke 1',
|
||||
'init true nil',
|
||||
'event tap debug_button',
|
||||
]);
|
||||
expect(diagnostics.entries.first.context, {'argumentCount': 2});
|
||||
});
|
||||
|
||||
test('rejects undeclared module imports', () async {
|
||||
final package = await _createPackage(
|
||||
mainScript: '''
|
||||
|
||||
Reference in New Issue
Block a user