From 052a24cfced0a0bdcfa2b9257845b58400b17301 Mon Sep 17 00:00:00 2001 From: CNlongY-Py <79128694+CNlongY-Py@users.noreply.github.com> Date: Mon, 11 May 2026 12:19:07 +0800 Subject: [PATCH] Create python_service_native.dart --- lib/core/services/python_service_native.dart | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 lib/core/services/python_service_native.dart diff --git a/lib/core/services/python_service_native.dart b/lib/core/services/python_service_native.dart new file mode 100644 index 000000000..1d33a2ab8 --- /dev/null +++ b/lib/core/services/python_service_native.dart @@ -0,0 +1,17 @@ +import 'package:pocketpy/pocketpy.dart' as pkpy; + +pkpy.VM? _vm; + +Future initPython() async { + _vm = pkpy.VM(); + // 可选:执行一些初始化脚本 + _vm?.exec('print("pocketpy ready")'); +} + +Future evalPythonCode(String code) async { + if (_vm == null) return; + _vm!.exec(code); + final out = _vm!.read_output(); + if (out.stdout.isNotEmpty) debugPrint('[Python stdout] ${out.stdout}'); + if (out.stderr.isNotEmpty) debugPrint('[Python stderr] ${out.stderr}'); +}