Closed iguanaonmystack closed 4 years ago
This was kind of just a hobby project for me, so it will take me a while to look through this. However this is great! Thanks!
No worries - these changes were a hobby project for me too!
This PR is amazing, merging!
Hi! I'm filing this pull request more as a heads-up than something I'm expecting will get merged, but thought you might like to know about its existence in case it's of any use to you, and to gauge interest before polishing it any further. (This was originally developed for a prototype project - https://github.com/iguanaonmystack/traingame-bot - and it works well enough for that, but well, prototypes are prototypes.)
This branch adds a new API, which I've dubbed the Full Object API for lack of a better idea, that provides access to arbitrary Python objects from JavaScript, and to arbitrary JavaScript objects from Python. I've updated README.md with a full example, or the prototype project linked above is essentially a full demo application.
The new API primarily provides:
import
rather thanimportFile
). The imported modules are returned themselves as wrapped Python objects using the same mechanics as any other wrapped Python objects (below), so don't require any additional top-level functions to interact with.None of the current PyNode functionality is replaced or altered.
I realise this deviates from PyNode's conventions in that everything is synchronous (ie, the function returns its result within the current thread, without a callback, deferred, etc). I'm relatively new to JavaScript (or at least, the last ten years of JavaScript) so perhaps I'm missing a trick here, but I was working on the basis that most existing Python modules one might want to call into, and/or provide callbacks for, will be expecting a synchronous API (ignoring for now Python's newish async/await syntax, which I haven't seen in the wild very often.)