-
Notifications
You must be signed in to change notification settings - Fork 45
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using RapydScript-ng in the browser #12
Comments
At http://www.glowscript.org/#/user/Bruce_Sherwood/folder/My_Programs/program/Users you can see what a huge impact RapydScript had on the use of glowscript.org. Previous to using RS, users had to write their 3D programs in JavaScript or CoffeeScript. The recent rapid rise in the number of users coincided with the introduction of VPython as an easier option. (One can also write programs in RapydScript, the distinction being that a GlowScript RapydScript program follows closely the API of GlowScript JavaScript programs, whereas GlowScript VPython programs involve some preprocessing to support the VPython API.) |
I'm not sure exactly what you are asking for. The most straight forward way to use RS-ng in the browser is to write you code in rapydscript and compile it to a javascript file and include the javascript file in your webpage. Do you mean you want to include the compiler itself in the browser and have it compile RS code to JavaScript on the fly? |
Oh and I was at Caltech from 2003-1009 in the Particle Theory Group -- long after your time there I'm afraid :) |
Yes, I want to include the compiler itself in the browser and have it
compile RS code to JavaScript on the fly. That's what I do currently. The
GlowScript libraries are written in JavaScript, and there is no reason to
rewrite them in RS. For an example of how this works, click here:
http://www.glowscript.org/#/user/GlowScriptDemos/folder/Examples/program/BinaryStar-VPython/edit
and you will see a (remarkably) short VPython program. Then click "Run this
program" and you will see the execution, a binary star. Both compilation
and execution are done in the browser, which means that the enterprise
scales well. The glowscript.org server only has to capture edit operations
and keep programs in a datastore (it's a Google App Engine application).
A major use of VPython in the browser is by students in intro physics
courses that use the Matter & Interactions textbook written by Ruth Chabay
and me (matterandinteractions.org). The students write small programs such
as the binary star program to model systems computationally. When I taught
at Caltech the textbook was the Feynman Lectures on Physics, which was a
huge stimulus to the curriculum development Ruth and I have carried out.
The science and engineering students who take our course typically have no
prior experience with programming, and the simplicity of Python and
VPython is essential to the enterprise. Even installing Python and the
VPython module is a big challenge for many of these students, let alone
building something using node. The user need not install anything, nor even
have to know anything about file systems.
Salvatore di Dio and Charles Law helped me get RS running in the browser,
but there never was any documentation on how to do this, and when a few
months ago I tried to upgrade RS I was unable to get the compiler to work
in the browser despite some help from Charles.
I was in Alvin Tollestrup's Users group and participated in experiments at
Berkeley and SLAC. Barry Barish, one of the principal scientists of LIGO,
was a colleague in that group.
|
RS-ng is designed from the ground up to be used in different contexts, so this should be easy enough. In fact, I am currently working on a LIVE (in browser) REPL (read-eval-print-loop) for RS-ng. If you checkout this repo from github, you can try it for yourself. Run bin/web-repl-export /path/to/some/empty/directory Then point your browser to |
A couple of caveats about the in browser REPL
|
Executing bin/web-repl-export /path/to/some/empty/directory gives the error
message that "bin/web-repl-export is not recognized as an internal or
external command, operable program or batch file." This is on Windows 10.
ES6 isn't yet an option for me, because for all I know users are scattered
across many browsers. Is there a switch that would for now make it possible
to compile in the browser but to old JavaScript?
Importing modules is not an issue for my purposes.
|
Ah, windows. bin/web-repl-export refers to the web-repl-export file in the bin subdirectory of this repo. To execute it on windows, you'd need to run node bin/web-repl-export (assuming you have installed node.js and it is on your path). As for non-ES6 runtimes, adding support for that would increase the size of the embedded compiler from 600KB to 6MB -- really not something I'd recommend doing. |
Thanks -- I successfully ran the program and ran index.html. I tried the
following and the "Compiled JavaScript" looks like ordinary JavaScript, not
ES6, though not yet being an ES6 user I might not know what to look for:
def add(x=10, y=35):
return x+y
print(add(y=100)) # 110
Given your REPL demonstration, is there a file in your repository that will
accept a string representing a Python program and return a string
representing compiled JavaScript or ES6 source?
|
I'm submitting this issue in order to make contact with you, not knowing your email address. I'm the developer of glowscript.org, which uses Tsepkov RapydScript to permit users to write Python programs that generate real-time navigable 3D animations extremely easily. For example, the one-line program "box()" creates a WebGL canvas, displays a white cube at the origin, provides useful lighting, positions the camera so that the box fills the screen, and turns on mouse controls for zooming and rotating the camera. Programs can be written and run even on mobile devices. See the Example programs at glowscript.org.
I like very much the enhancements you have made and would like to use your version of RS, and like you I'm concerned that evidently Tsepkov now has little time to devote to improving RS. I had difficulties using standard RS in the client and have no interest in using it in a server or with node. I would be thrilled if you could tell me how to use your version of RS in the browser. Thanks much.
Bruce Sherwood ([email protected])
P.S. I taught at Caltech 1966-1969, then switched to college physics education, including the use of computers.
The text was updated successfully, but these errors were encountered: