I was experimenting with py2js a bit again, for some game-type library
experimenting (this time, trying to get some very basic pygame apps to
run in the brower, after running through py2js, and providing basic
javascript wrappers around canvas/some other js libs).
Noticed a couple of py2js issues;
1. import statement isn't supported.
Kind of makes sense, since there's no direct javascript analogy. The
closest might be something like "require ('module')" from CommonJS
(also used in gamejs lib).
From my side, I'm considering automatically converting "import"
statements into either "require" statements (before running py2js), or
including those deps as separate <script> lines in the generated html.
Is there a plan to add some kind of basic import statement?
Also, I heard something about writing modules. Does that mean
re-implementing maths, os, etc, in javascript? (similar to with
shedskin - the common libs are re-implemented in C++).
(Another interesting possibility is writing the supporting modules in
python, and use py2js to convert to javascript).
2. try/except isn't supported
The generated javascript code includes javascript try/except, but you
can't use this on the Python level. Is support for this planned?
3. class.class.class.method() doesn't seem to work
I was trying to implement some basic wrapper py2js classes for pygame, eg:
class pygame:
class display
@staticmethod
def set_mode(size):
# TODO: Logic goes here
I was able to declare that, but later, this type of logic didn't work.
Firebug was reporting errors along the lines of the set_mode method
doens't exist.
So instead, I had to flatten out the inner classes like this:
class pygame_display:
@staticmethod
def set_mode(size):
# TODO: Logic goes here
Which does work.
I also tried tricks like this:
pygame.display = pygame_display
But that had problems too. iirc, calling pygame.display.set_mode() no
longer returns the object in JS, despite having a return line, which
works fine in the "flattened" version.
(I may need to do something like automatically convert pygame.display
to pygame_display, before calling py2js)
Are these Javascript limitations, or possibly a bug in py2js?
4. Problems with compound inequality comparisons:
Logic like this doesn't work:
if a <= b <= c:
I needed to convert to:
if (a <= b) and (b <= c)
5. Problems with tupple/list index access.
I don't have the code in front of me at the moment, but basically
setting and assigning list indexes has issues, where the generated js
has __getitem__ and __setitem__ code that javascript doesn't like.
This being in purely py2js code, without trying to interface with
native Arrays or similar. This looks like a different problem to the
one I had with the examples.
Thanks,
David.
Hi,
I was experimenting with py2js a bit again, for some game-type library
experimenting (this time, trying to get some very basic pygame apps to
run in the brower, after running through py2js, and providing basic
javascript wrappers around canvas/some other js libs).
Noticed a couple of py2js issues;
1. import statement isn't supported.
Kind of makes sense, since there's no direct javascript analogy. The
closest might be something like "require ('module')" from CommonJS
(also used in gamejs lib).
From my side, I'm considering automatically converting "import"
statements into either "require" statements (before running py2js), or
including those deps as separate <script> lines in the generated html.
Is there a plan to add some kind of basic import statement?
Also, I heard something about writing modules. Does that mean
re-implementing maths, os, etc, in javascript? (similar to with
shedskin - the common libs are re-implemented in C++).
(Another interesting possibility is writing the supporting modules in
python, and use py2js to convert to javascript).
2. try/except isn't supported
The generated javascript code includes javascript try/except, but you
can't use this on the Python level. Is support for this planned?
3. class.class.class.method() doesn't seem to work
I was trying to implement some basic wrapper py2js classes for pygame, eg:
class pygame:
class display
@staticmethod
def set_mode(size):
# TODO: Logic goes here
I was able to declare that, but later, this type of logic didn't work.
Firebug was reporting errors along the lines of the set_mode method
doens't exist.
So instead, I had to flatten out the inner classes like this:
class pygame_display:
@staticmethod
def set_mode(size):
# TODO: Logic goes here
Which does work.
I also tried tricks like this:
pygame.display = pygame_display
But that had problems too. iirc, calling pygame.display.set_mode() no
longer returns the object in JS, despite having a return line, which
works fine in the "flattened" version.
(I may need to do something like automatically convert pygame.display
to pygame_display, before calling py2js)
Are these Javascript limitations, or possibly a bug in py2js?
4. Problems with compound inequality comparisons:
Logic like this doesn't work:
if a <= b <= c:
I needed to convert to:
if (a <= b) and (b <= c)
5. Problems with tupple/list index access.
I don't have the code in front of me at the moment, but basically
setting and assigning list indexes has issues, where the generated js
has __getitem__ and __setitem__ code that javascript doesn't like.
This being in purely py2js code, without trying to interface with
native Arrays or similar. This looks like a different problem to the
one I had with the examples.
Thanks,
David.
On Sun, Mar 6, 2011 at 11:59 PM, Samuel Ytterbrink <nep...@gmail.com> wrote:
> to be short... we know that its broken.. and using the "new" py2js is like
> using something worse then a alpha.
> How ever we are grateful that you try to use it, and i will try to answer
> the questions i can.
I agree with what Sam said. Those are things that are not implemented yet.
We welcome any help with any of these. You can participate in the
mailinglist, help us review code, send new pull requests, or just test
what is there and report bugs. Whatever you feel is the best use of
your skills/time.
Ondrej