From ee2d69dcd6b2e752ea10c8cc3db258d960c2854b Mon Sep 17 00:00:00 2001 From: blueloveTH Date: Sat, 24 Jun 2023 21:10:24 +0800 Subject: [PATCH] ... --- docs/unity/console.md | 32 ++++++++++++++++++++++++++++++++ docs/unity/introduction.md | 6 +++--- 2 files changed, 35 insertions(+), 3 deletions(-) create mode 100644 docs/unity/console.md diff --git a/docs/unity/console.md b/docs/unity/console.md new file mode 100644 index 00000000..9d576098 --- /dev/null +++ b/docs/unity/console.md @@ -0,0 +1,32 @@ +--- +label: Python Console +icon: dot +order: 5 +--- + +You can open the Python console in Unity by clicking the `Window/Python Console` menu item. + +By default, the console creates a unmodified `VM` instance to execute your code. +You may want to provide an enhanced `VM` instance for the console in Unity Editor. +For example, adding some class bindings in `UnityEngine` namespace. + +To do this, you need to create a class derived from `VM` and put it in `Assets/Editor/` folder. +By adding `[EditorVM]` attribute to the class, +the console will use it instead of the default `VM` instance. + + +```csharp +using UnityEngine; +using PocketPython; + +[EditorVM] // this attribute is required +public class EnhancedVM: VM{ + public EnhancedVM() { + RegisterAutoType(builtins); + RegisterAutoType(builtins); + RegisterAutoType(builtins); + RegisterAutoType(builtins); + // ... + } +} +``` \ No newline at end of file diff --git a/docs/unity/introduction.md b/docs/unity/introduction.md index c4ec1c3d..b2aaa1e0 100644 --- a/docs/unity/introduction.md +++ b/docs/unity/introduction.md @@ -43,7 +43,7 @@ The features marked with `YES` are supported, and the features marked with `NO` | Unpacking | `a, b = 1, 2` | YES | YES | | Star Unpacking | `a, *b = [1, 2, 3]` | YES | YES | | Exception | `raise/try..catch` | YES | NO | -| Dynamic Code | `eval()/exec()` | YES | NO | +| Dynamic Code | `eval()/exec()` | YES | YES | | Reflection | `hasattr()/getattr()/setattr()` | YES | YES | | Import | `import/from..import` | YES | YES | | Context Block | `with as :` | YES | NO | @@ -65,7 +65,7 @@ which means passing arguments between C# and Python is extremely easy and intuit | Python Type | C# Type | | ----------- | ------- | -| `None` | `PocketPy.NoneType` | +| `None` | `NoneType` | | `object` | `System.Object` | | `bool` | `System.Boolean` | | `int` | `System.Int32` | @@ -73,7 +73,7 @@ which means passing arguments between C# and Python is extremely easy and intuit | `str` | `System.String` | | `tuple` | `System.Object[]` | | `list` | `System.Collections.Generic.List` | -| `dict` | `System.Collections.Generic.Dictionary` | +| `dict` | `System.Collections.Generic.Dictionary` | | ... | ... | ### Python Console in Editor