blueloveTH 3 gadi atpakaļ
vecāks
revīzija
8bc04389c8

+ 24 - 11
plugins/unity/com.bl.pocketpy/JsonRpcServer.cs

@@ -1,18 +1,31 @@
+using PlasticPipe.PlasticProtocol.Messages;
+using System;
 using System.Collections;
 using System.Collections.Generic;
-using UnityEngine;
+using System.Threading.Tasks;
 
-public class JsonRpcServer : MonoBehaviour
+namespace pkpy
 {
-    // Start is called before the first frame update
-    void Start()
+    public abstract class JsonRpcServer
     {
-        
-    }
+        protected abstract Task<string> dispatch(ThreadedVM vm, string request);
 
-    // Update is called once per frame
-    void Update()
-    {
-        
+        public async Task attach(ThreadedVM vm)
+        {
+            while (vm.state <= ThreadState.running) await Task.Yield();
+            switch (vm.state)
+            {
+                case ThreadState.suspended:
+                    string request = vm.read_jsonrpc_request();
+                    string response = await dispatch(vm, request);
+                    vm.write_jsonrpc_response(response);
+                    await attach(vm);
+                    break;
+                case ThreadState.finished:
+                    break;
+                default:
+                    throw new Exception("Unexpected state");
+            }
+        }
     }
-}
+}

+ 11 - 0
plugins/unity/com.bl.pocketpy/PocketPy.cs.meta

@@ -0,0 +1,11 @@
+fileFormatVersion: 2
+guid: dd15753450212f045aa08d30ba3cca6e
+MonoImporter:
+  externalObjects: {}
+  serializedVersion: 2
+  defaultReferences: []
+  executionOrder: 0
+  icon: {instanceID: 0}
+  userData: 
+  assetBundleName: 
+  assetBundleVariant: