Live data from Hacker News

PyPy.js: A fast, compliant Python implementation for the web

pypyjs.org

41–50 of 144 posts

Re: PyPy.js: A fast, compliant Python implementation for the web

#43
post #22

Earlier quoted context omitted.

have you looked into CoffeeScript? it's slightly more pythonic than JavaScript.

There's raypidscript also: http://www.rapydscript.com/ which is a python like JS precompiler ( https://news.ycombinator.com/item?id=9385596 ) I haven't had the time to try it yet, but maybe it'll suit your needs ;)

Right of the bat their example puts me off. I mean.. come on.

    self.$popup = $('#' + containerId).addClass('pop-up').mouseout(def():
        self.hide()
    )

Re: PyPy.js: A fast, compliant Python implementation for the web

#44
post #23

Earlier quoted context omitted.

> python can't be directly included in Firefox or other browsers So Python is a bad candidate, but there are better candidates out there. For example, jsofocaml (using OCaml in the browser) looks quite promising. In the end, we need a lightweight yet properly defined and highlevel language, and the ML languages as well as the LISP languages are great candidates for that.

Purescript is a Haskell-like language that is designed to output to javascript. It looks quite nice and has seen a lot of attention lately. It's even in GSoC.

Also, ClojureScript.

Re: PyPy.js: A fast, compliant Python implementation for the web

#45
post #18

Sample code to execute some Javascript code inside PyPy.js. I couldn't find any examples. import js js.eval("console.log(\"hi!\")")

It's a bit messy, but:

    js.eval('var div = document.createElement("div"); div.style.width = "100px"; div.style.height = "100px"; div.style.background = "red"; div.style.color = "white"; div.innerHTML = "Hello"; document.body.appendChild(div);');
manages to append a div.

--

Directly modifying document.body.innerHTML in any way seems to hang it. Both:

    js.eval('document.body.innerHTML += "";');
    js.globals.document.body.innerHTML += ""
Cause it to hang, though the javascript console shows it was added (or using an img tag instead).

(ChromeOS v43 beta)

Re: PyPy.js: A fast, compliant Python implementation for the web

#46
post #25

Earlier quoted context omitted.

Or this: import js js.globals.console.log('hi!')

I'm loving this, my head is reeling with the glint of possibilities import js js.globals.console.log('hi!'*5)

Seems to be some issues with the interop still, eg:

  import js
  >>> "globals" in dir(js)
  True
  >>> "console" in dir(js.globals)
  False
  >>> js
  
  >>> js.globals.console
  
So apparently introspection doesn't quite work with the wrapped js. Also, if you try: "[ i for i in js.globals]" (or equivalently iterate/loop over the globals-object) - the whole repl/tab hangs.

Not really an issue for running business logic in the browser, but if this was a full python repl-interface (with ipython support!) to the whole browser DOM -- that'd be a fantastic tool.

Re: PyPy.js: A fast, compliant Python implementation for the web

#47
post #18

Sample code to execute some Javascript code inside PyPy.js. I couldn't find any examples. import js js.eval("console.log(\"hi!\")")

Just playing around:

    import js
    c = js.globals.document.createElement("canvas")
    js.globals.document.body.appendChild(c)
    ctx = c.getContext("2d")
    ctx.fillRect(10, 10, 10, 10)
Edit: Here is a simple animation:

    import js
    import math
    import time
    c = js.globals.document.createElement("canvas")
    js.globals.document.body.appendChild(c)
    ctx = c.getContext("2d")
    
    def render():
      ctx.clearRect(0, 0, c.width, c.height)
      t = time.time()
      ctx.fillRect(20+math.sin(t*10)*10, 20+math.cos(t*10)*10, 10, 10)
    
    js.globals.window.setInterval(render, 20)
Here's a version you can paste in properly: http://pastebin.com/raw.php?i=67GadSUV

Re: PyPy.js: A fast, compliant Python implementation for the web

#48
post #18

Sample code to execute some Javascript code inside PyPy.js. I couldn't find any examples. import js js.eval("console.log(\"hi!\")")

It's a bit messy, but: js.eval('var div = document.createElement("div"); div.style.width = "100px"; div.style.height = "100px"; div.style.background = "red"; div.style.color = "white"; div.innerHTML = "Hello"; document.body.appendChild(div);'); manages to append a div. -- Directly modifying document.body.innerHTML in any way seems to hang it. Both: js.eval('document.body.innerHTML += " ";'); js.globals.document.body.…

[deleted]

Re: PyPy.js: A fast, compliant Python implementation for the web

#49

Sadly, "import antigravity" doesn't work

I was more disappointed (but not surprised!) that "import pip" didn't work.

If it did (and it has big ramifications for how much of "python" (for some definition of "python" that includes most of the standard library) works. Eg sockets, interacting with some sort of "local" "file-system" etc) one could (this is handy if working on windows, and running python via cmd-r python.exe):

  import pip
  # pip.main expects a list of arguments, hence .split() 
  pip.main("install ipython".split())
     # Only needed first
     # time, as it installs ipython under site-packages.
     # Only works if the user has write access, obviously

  import IPython
  IPython.start_ipython()

Re: PyPy.js: A fast, compliant Python implementation for the web

#50
post #18

Sample code to execute some Javascript code inside PyPy.js. I couldn't find any examples. import js js.eval("console.log(\"hi!\")")

It would be good if they could support a common api with brython, which has "import web" and some other bits...

I guess these things will take a while to shake out, but I'd imagine a python-in-browser-api PEP at some point.

Post reply on HN