Package: unitypython
UnityPythonKey points:Run a Python-like programming language on ALL platforms such as iOS, Android, etc.Good IDE support via Pylance, type checked! (seeunitypython-typeshed)Dynamic and fast code loading in Unity. Edit code and see how UI changes immediately (Unity Editor is painful to me)!An extensible coroutine implementation.asyncandawaitare not as restricted as that in CPython and can be used as fast/fine-grained controlled event loops in game development.UnityPython is based on CPython 3.10, but not fully compatible to CPython. For instance,StopIterationis not used for loop constructs (exceptions are heavy and not used for control flow);typeis the only metaclass, etc.importUnityEngineclassMyComponent(UnityEngine.MonoBehaviour):defStart(self):asyncdefcoro():whilenotcond_satisfied:awaitTask.Yielddo_something()defcoro2():whilenotcond_satisfied:yielddo_something()self.StartCoroutine(coro())self.StartCoroutine(coro2())ContributingSee0.1 roadmapBasic development workflow:cd UnityPython.FrontEnd && pip install -e . && cd ..; requires Python 3.8+ (Python 3.10 is better)cd UnityPython.BackEnddotnet restorebash build-code.sh && bash runtests.shUnityPython.BackEnd/tests/test_*.pywill be executed.Besides, we badly need more tests! Help us and refertest_semantics.How to add a method to datatypes? (concise way)[PyBind]can be used to bind Python methods. You can bind a Pythonstaticmethodor instance method through the following the steps:implement an instacne/static method/instance property[PyBind]publicTrObjectappend(TrObjectelt){container.Add(elt);returnMK.None();}build an DLL forUnityPython.BackEnddotnet public -c Releasecodegen usingUnityPython.BackEnd.CodeGendotnet run --project ../UnityPython.BackEnd.CodeGen/UnityPython.BackEnd.CodeGen.csprojThenappendis bound.[PyBind]works for static methods and properties as well. Default arguments work.NOTE: functions annotated by[PyBind]must take a return value!!!How to add a method to datatypes? (verbose way)For example, if we want to implementappendforlist,we firstly get toUnityPython.BackEnd/src/Traffy.Objects/List.csthen we find the method annotated with[Mark(Initialization.TokenClassInit)]see the codepublicstaticTrObjectappend(TrObjectself,TrObjectvalue){((TrList)self).container.Add(value);returnRTS.object_none;// RTS = runtime support}[Mark(Initialization.TokenClassInit)]staticvoid_Init(){CLASS=TrClass.FromPrototype<TrList>();CLASS.Name="list";CLASS.InitInlineCacheForMagicMethods();CLASS[CLASS.ic__new]=TrStaticMethod.Bind("list.__new__",TrList.datanew);// 1. 'TrSharpFunc.FromFunc' converts a CSharp function to UnityPython 'builtin_function'// 2. 'CLASS["somemethod".ToIntern()] = python-object' is equal to something like//      class list://         somemethod = exprCLASS["append".ToIntern()]=TrSharpFunc.FromFunc("list.append",TrList.append);...}PS:TrSharpFunc.FromFunccreates a methodTrStaticMethod.Bindcreates astaticmethodTrClassMethod.Bindcreates aclassmethodTrProperty.Create(getter=null, setter=null)creates apropertyHow to add a builtin-functionBasically, you just need to callInitialization.Prelude(string name, TrObject o).For maintainability, please collect all builtin callables (other than datatypes) atUnityPython.BackEnd/src/Builtins.csnamespaceTraffy{publicstaticclassBuiltins{staticIEnumerator<TrObject>mkrange(intstart,intend,intstep){for(inti=start;i<end;i+=step)yieldreturnMK.Int(i);}// BLists, or double-ended lists, are designed for fast method call (requires adding a 'self' to the left end)staticTrObjectrange(BList<TrObject>args,Dictionary<TrObject,TrObject>kwargs){varnarg=args.Count;switch(narg){case1:returnMK.Iter(mkrange(0,args[0].AsInt(),1));case2:returnMK.Iter(mkrange(args[0].AsInt(),args[1].AsInt(),1));case3:returnMK.Iter(mkrange(args[0].AsInt(),args[1].AsInt(),args[2].AsInt()));default:thrownewTypeError($"range() takes 1 to 3 positional argument(s) but {narg} were given");}}[Mark(Initialization.TokenBuiltinInit)]publicstaticvoidInitRuntime(){Initialization.Prelude(TrSharpFunc.FromFunc("range",range));}}}