translating classes to javascript
Hi list, I'm fairly new to pypy and was only doing some experimenting with the javascript translator so far. First of all let me say that the whole project is pretty amazing! After translating a couple of functions I tried translating a class, but was unsuccessful so far but since the docs mention supporting inheritance I guess this should be possible. Is it? For instance if I have in RPython the following: class test: def __init__( self, value ): self.value = value def meth1( self ): return self.value def meth2( self ): do_something_which_is_translatable( ) then how do I get the corresponding javascript code? Since the docs say jscompile should be invoked by 'jscompile module function_names' I'm kind of lost. The same holds for rpython2javascript it expects a list of functions. Any insight or comment would be very helpful. --------------------------------- Need Mail bonding? Go to the Yahoo! Mail Q&A for great tips from Yahoo! Answers users.
John Smith wrote:
Hi list,
I'm fairly new to pypy and was only doing some experimenting with the javascript translator so far. First of all let me say that the whole project is pretty amazing!
After translating a couple of functions I tried translating a class, but was unsuccessful so far but since the docs mention supporting inheritance I guess this should be possible. Is it?
For instance if I have in RPython the following:
class test: def __init__( self, value ): self.value = value def meth1( self ): return self.value def meth2( self ): do_something_which_is_translatable( )
then how do I get the corresponding javascript code? Since the docs say jscompile should be invoked by 'jscompile module function_names' I'm kind of lost. The same holds for rpython2javascript it expects a list of functions.
Any insight or comment would be very helpful.
------------------------------------------------------------------------ Need Mail bonding? Go to the Yahoo! Mail Q&A <http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&sid=396546091> for great tips from Yahoo! Answers <http://answers.yahoo.com/dir/index;_ylc=X3oDMTFvbGNhMGE3BF9TAzM5NjU0NTEwOARfcwMzOTY1NDUxMDMEc2VjA21haWxfdGFnbGluZQRzbGsDbWFpbF90YWcx?link=ask&sid=396546091> users. ------------------------------------------------------------------------
_______________________________________________ pypy-dev@codespeak.net http://codespeak.net/mailman/listinfo/pypy-dev Hi John!
Because usual way of invoking javascript on your browser is to call a function, you need a function where you'll begin. Like: # class test as above def f(): test_instance = test(3) test_instance.meth() and translate function f. Your class will magically appear in translated javascript. Cheers, fijal
I'm fairly new to pypy and was only doing some experimenting with the javascript translator so far. First of all let me say that the whole project is pretty amazing!
After translating a couple of functions I tried translating a class, but was unsuccessful so far but since the docs mention supporting inheritance I guess this should be possible. Is it?
For instance if I have in RPython the following:
class test: def __init__( self, value ): self.value = value def meth1( self ): return self.value def meth2( self ): do_something_which_is_translatable( )
then how do I get the corresponding javascript code? Since the docs say jscompile should be invoked by 'jscompile module function_names' I'm kind of lost. The same holds for rpython2javascript it expects a list of functions.
Any insight or comment would be very helpful.
Because usual way of invoking javascript on your browser is to call a function, you need a function where you'll begin. Like: # class test as above def f(): test_instance = test(3) test_instance.meth() and translate function f. Your class will magically appear in translated javascript. Thanks very much for the reply, I can certainly do things this way however being able to call methods directly sounds like a reasonable thing to me (both in python and in JS). Are there plans for adding this kind of functionality or there are reasons why you think this is not necessary? Cheers, John --------------------------------- Bored stiff? Loosen up... Download and play hundreds of games for free on Yahoo! Games.
John Smith wrote:
> I'm fairly new to pypy and was only doing some experimenting with the > javascript translator so far. First of all let me say that the whole > project is pretty amazing! > > After translating a couple of functions I tried translating a class, > but was unsuccessful so far but since the docs mention supporting > inheritance I guess this should be possible. Is it? > > For instance if I have in RPython the following: > > class test: > def __init__( self, value ): > self.value = value > def meth1( self ): > return self.value > def meth2( self ): > do_something_which_is_translatable( ) > > then how do I get the corresponding javascript code? Since the docs > say jscompile should be invoked by 'jscompile module function_names' > I'm kind of lost. The same holds for rpython2javascript it expects a > list of functions. > > Any insight or comment would be very helpful. >
Because usual way of invoking javascript on your browser is to call a function, you need a function where you'll begin. Like:
# class test as above
def f(): test_instance = test(3) test_instance.meth()
and translate function f. Your class will magically appear in translated javascript.
Thanks very much for the reply, I can certainly do things this way however being able to call methods directly sounds like a reasonable thing to me (both in python and in JS). Are there plans for adding this kind of functionality or there are reasons why you think this is not necessary?
Yes there are plans for such support, while there was no time to implement it yet :-( The list of ideas lay down here: http://codespeak.net/pypy/dist/pypy/doc/js/todo.html Cheers, fijal
<OT> I'm really sorry for the messed up layout, yahoo mail sucks big time.... </OT> --------------------------------- Access over 1 million songs - Yahoo! Music Unlimited.
participants (2)
-
John Smith
-
Maciek Fijalkowski