Some missing py2js syntax

12 views
Skip to first unread message

David

unread,
Mar 7, 2011, 2:30:14 AM3/7/11
to py...@googlegroups.com
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.

Samuel Ytterbrink

unread,
Mar 7, 2011, 2:59:57 AM3/7/11
to py...@googlegroups.com
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.

2011/3/7 David <wizz...@gmail.com>

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.

known but not tracked,  make an issue on the qsnake branch.
 
 

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.

We should __NOT__ generate html thats is for the user to do.
 
Is there a plan to add some kind of basic import statement?

Yes! its the first priority after fixing the general Desigen of the Compiler, as it is now it only supports one mode and becuse of that it creates the known __setattr__ errors.


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).

Thats one goal. Importing javascript modules, as well as being able to import py2js modules in javascript, is also a goal.
 

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?

known but not tracked add a issue ion the qsnake branch.
 

3. class.class.class.method() doesn't seem to work

Unknown and not tracked.
if you can make a test, and send a pull request, it would be Great!


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?

Probably Bugs, we got tons of them :D, but we are working on most of them att the same time. so some time 'soon' we will have if not fewer at least different.
 

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)

 
i have solved this myself in a old branch of the project while playing around and it will get fixed the right way some time in the feature, just rewrite things in the meantime. 

But make a issue, and a test!?, so that we don't forget and can track the progress.

 
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.

once a gain thx, it is great that we now seams to be 4 people at this mailing list.

--
//Samuel Ytterbrink

Ondrej Certik

unread,
Mar 7, 2011, 3:06:45 AM3/7/11
to py...@googlegroups.com, Samuel Ytterbrink
Hi 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

Reply all
Reply to author
Forward
0 new messages