Open linsmod opened 9 months ago
Interesting use case! I think the most help I can be here is to steer you in another direction. The TypeScript supported by pxt is a tiny subset of the actual language, and doesn't implement basic APIs like Object.defineProperty. Have you considered trying QuickJS? It is quite nice, and friendly to embedded scenarios. https://bellard.org/quickjs/, https://github.com/bellard/quickjs
Yes, I did think about using QuickJS, its a small and clear lib benefits browser-like projects, but I chose pxt finnaly. One reason I chose Typescript is because I prefer Strong Type programming language, and the Typescript subset used by pxt fits my requirements: StrongTyped, clearly and simple Type System suite for small devices.
Another reason, some guys always like to do things that have not been done by somebody yet, like me ^^.
I did one other experiment with pxt.dll, instantiating a pxt-arcade game within a Unity project: https://github.com/eanders-ms/arcade-unity-demo. I may be informative to see how the dll was instantiated, via C# P/invoke, in this case: https://github.com/eanders-ms/arcade-unity-demo/blob/main/Assets/Plugins/pxt/Pxt.cs
One thing to note is that pxt.dll is a runtime, not a compiler. It cannot load JavaScript, only compiled binaries.
How I managed to get a compiled binary for the dll was not straightforward. I believe it involved running one of the pxt targets (pxt-arcade or pxt-microbit) on localhost and tweaking the code to force it to build the dll's format. There is probably better way, but I don't know it.
Funny experiment!
var rom = Resources.Load<TextAsset>("roms/castle-crawler.pxt64");
VmStartBuffer(rom.bytes, rom.bytes.Length);
As you said, the way to get the rom(actually generated by a ts-to-vmBytecode compilier, and the compiler is implemented by typescript) and the runtime(pxt.dll) needs some tweaking, about , like choosing the 'dockermake' or 'arcadedocker' targets or changing the build parameter to force local build,, --forceLocal. I need to go back to review the PXT or PXT-Arcade's code to get more insights.
I'm wondering to porting the pxt runtime into a mini browser to act as a scriptEngine like js, because the mini browser has no js support currently...
Before I saw you project, I built the pxtVM success but I have no payload can be run.
I noticed the compiler is written by Typescript and have a deep binding to PXT, I'm not familar with the typescript lang, It's absolutly not friendly to me if I want split it out from PXT.
What was I tried run:
Do you know how to let a compiler to compile the typescript codes to the vm playload format?