mirror of
https://github.com/pocketpy/pocketpy
synced 2025-11-05 11:10:17 +00:00
Compare commits
2 Commits
f22f61ac80
...
31649a32b2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
31649a32b2 | ||
|
|
1b53568733 |
@ -1,92 +1,5 @@
|
|||||||
# pocketpy
|
# pocketpy
|
||||||
|
|
||||||
A new Flutter FFI plugin project.
|
Official FFI bindings for pocketpy.
|
||||||
|
|
||||||
## Getting Started
|
|
||||||
|
|
||||||
This project is a starting point for a Flutter
|
|
||||||
[FFI plugin](https://docs.flutter.dev/development/platform-integration/c-interop),
|
|
||||||
a specialized package that includes native code directly invoked with Dart FFI.
|
|
||||||
|
|
||||||
## Project structure
|
|
||||||
|
|
||||||
This template uses the following structure:
|
|
||||||
|
|
||||||
* `src`: Contains the native source code, and a CmakeFile.txt file for building
|
|
||||||
that source code into a dynamic library.
|
|
||||||
|
|
||||||
* `lib`: Contains the Dart code that defines the API of the plugin, and which
|
|
||||||
calls into the native code using `dart:ffi`.
|
|
||||||
|
|
||||||
* platform folders (`android`, `ios`, `windows`, etc.): Contains the build files
|
|
||||||
for building and bundling the native code library with the platform application.
|
|
||||||
|
|
||||||
## Building and bundling native code
|
|
||||||
|
|
||||||
The `pubspec.yaml` specifies FFI plugins as follows:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
plugin:
|
|
||||||
platforms:
|
|
||||||
some_platform:
|
|
||||||
ffiPlugin: true
|
|
||||||
```
|
|
||||||
|
|
||||||
This configuration invokes the native build for the various target platforms
|
|
||||||
and bundles the binaries in Flutter applications using these FFI plugins.
|
|
||||||
|
|
||||||
This can be combined with dartPluginClass, such as when FFI is used for the
|
|
||||||
implementation of one platform in a federated plugin:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
plugin:
|
|
||||||
implements: some_other_plugin
|
|
||||||
platforms:
|
|
||||||
some_platform:
|
|
||||||
dartPluginClass: SomeClass
|
|
||||||
ffiPlugin: true
|
|
||||||
```
|
|
||||||
|
|
||||||
A plugin can have both FFI and method channels:
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
plugin:
|
|
||||||
platforms:
|
|
||||||
some_platform:
|
|
||||||
pluginClass: SomeName
|
|
||||||
ffiPlugin: true
|
|
||||||
```
|
|
||||||
|
|
||||||
The native build systems that are invoked by FFI (and method channel) plugins are:
|
|
||||||
|
|
||||||
* For Android: Gradle, which invokes the Android NDK for native builds.
|
|
||||||
* See the documentation in android/build.gradle.
|
|
||||||
* For iOS and MacOS: Xcode, via CocoaPods.
|
|
||||||
* See the documentation in ios/pocketpy.podspec.
|
|
||||||
* See the documentation in macos/pocketpy.podspec.
|
|
||||||
* For Linux and Windows: CMake.
|
|
||||||
* See the documentation in linux/CMakeLists.txt.
|
|
||||||
* See the documentation in windows/CMakeLists.txt.
|
|
||||||
|
|
||||||
## Binding to native code
|
|
||||||
|
|
||||||
To use the native code, bindings in Dart are needed.
|
|
||||||
To avoid writing these by hand, they are generated from the header file
|
|
||||||
(`src/pocketpy.h`) by `package:ffigen`.
|
|
||||||
Regenerate the bindings by running `flutter pub run ffigen --config ffigen.yaml`.
|
|
||||||
|
|
||||||
## Invoking native code
|
|
||||||
|
|
||||||
Very short-running native functions can be directly invoked from any isolate.
|
|
||||||
For example, see `sum` in `lib/pocketpy.dart`.
|
|
||||||
|
|
||||||
Longer-running functions should be invoked on a helper isolate to avoid
|
|
||||||
dropping frames in Flutter applications.
|
|
||||||
For example, see `sumAsync` in `lib/pocketpy.dart`.
|
|
||||||
|
|
||||||
## Flutter help
|
|
||||||
|
|
||||||
For help getting started with Flutter, view our
|
|
||||||
[online documentation](https://flutter.dev/docs), which offers tutorials,
|
|
||||||
samples, guidance on mobile development, and a full API reference.
|
|
||||||
|
|
||||||
|
https://github.com/pocketpy/pocketpy
|
||||||
@ -1,6 +1,6 @@
|
|||||||
name: pocketpy
|
name: pocketpy
|
||||||
description: A lightweight Python interpreter for game engines. It supports Android/iOS/Windows/Linux/MacOS.
|
description: A lightweight Python interpreter for game engines. It supports Android/iOS/Windows/Linux/MacOS.
|
||||||
version: 2.0.0
|
version: 2.0.1+5
|
||||||
homepage: https://pocketpy.dev
|
homepage: https://pocketpy.dev
|
||||||
repository: https://github.com/pocketpy/pocketpy
|
repository: https://github.com/pocketpy/pocketpy
|
||||||
|
|
||||||
|
|||||||
@ -13,7 +13,8 @@ static py_TValue _True, _False, _None, _NIL;
|
|||||||
|
|
||||||
void py_initialize() {
|
void py_initialize() {
|
||||||
if(pk_current_vm){
|
if(pk_current_vm){
|
||||||
c11__abort("py_initialize() can only be called once!");
|
// c11__abort("py_initialize() can only be called once!");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MemoryPools__initialize();
|
MemoryPools__initialize();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user