@@ -830,14 +830,16 @@ def _visit_js_classdef(self, node):
830830 else :
831831 class_decorators .append ( decorator )
832832
833+ method_names = [] ## write back in order (required by GLSL)
833834 methods = {}
834835 class_vars = []
835836
836837 for item in node .body :
837838 if isinstance (item , FunctionDef ):
839+ method_names .append (item .name )
838840 methods [ item .name ] = item
839841 if self .is_gpu_method ( item ):
840- item .args .args [0 ].id = name ## change self to the class name
842+ item .args .args [0 ].id = name ## change self to the class name, pythonjs.py changes it to 'ClassName self'
841843 else :
842844 item .args .args = item .args .args [1 :] ## remove self
843845 finfo = inspect_function ( item )
@@ -901,9 +903,9 @@ def _visit_js_classdef(self, node):
901903 writer .write ('%s.__uid__ = "" + _PythonJS_UID' % name )
902904 writer .write ('_PythonJS_UID += 1' )
903905
904- keys = methods .keys ()
905- keys .sort ()
906- for mname in keys :
906+ # keys = methods.keys()
907+ # keys.sort()
908+ for mname in method_names :
907909 method = methods [mname ]
908910 gpu_method = False
909911 for dec in method .decorator_list :
@@ -913,8 +915,10 @@ def _visit_js_classdef(self, node):
913915
914916 if gpu_method :
915917 method .name = '%s_%s' % (name , method .name )
918+ self ._in_gpu_method = name ## name of class
916919 line = self .visit (method )
917920 if line : writer .write ( line )
921+ self ._in_gpu_method = None
918922
919923 else :
920924
@@ -2072,13 +2076,18 @@ def visit_Call(self, node):
20722076 raise SyntaxError ( self .format_error (node ) )
20732077
20742078 elif self ._with_ll or name == 'inline' or self ._with_glsl :
2079+ F = self .visit (node .func )
20752080 args = [self .visit (arg ) for arg in node .args ]
2081+ if hasattr (self , '_in_gpu_method' ) and self ._in_gpu_method and isinstance (node .func , ast .Attribute ):
2082+ F = '%s_%s' % (self ._in_gpu_method , node .func .attr )
2083+ args .insert (0 , 'self' )
2084+
20762085 if node .keywords :
20772086 args .extend ( [self .visit (x .value ) for x in node .keywords ] )
2078- return '%s(%s)' % ( self . visit ( node . func ) , ',' .join (args ) )
2087+ return '%s(%s)' % ( F , ',' .join (args ) )
20792088
20802089 else :
2081- return '%s(%s)' % ( self . visit ( node . func ) , ',' .join (args ) )
2090+ return '%s(%s)' % ( F , ',' .join (args ) )
20822091
20832092 elif self ._with_js or self ._with_dart :
20842093 args = list ( map (self .visit , node .args ) )
0 commit comments