Permalink
Browse files

added new style to declare the type of a variable using the special f…

…unction: var(x=SomeType)
  • Loading branch information...
hartsantler committed Oct 4, 2013
1 parent b772e3b commit 71d5664467b7c3c8130a7e1bcf727217ea30d88d
Showing with 25 additions and 5 deletions.
  1. +10 −0 bindings/three.py
  2. +7 −5 pythonscript/python_to_pythonjs.py
  3. +8 −0 tests/threejs_vector3.html
View
@@ -64,6 +64,16 @@ def add(self, other):
self.set( self.x+other.x, self.y+other.y, self.z+other.z )
return self
+ def addScalar(self, s):
+ self.set( self.x+s, self.y+s, self.z+s )
+ return self
+
+ def addVectors(self, a,b):
+ var( a=Vector3, b=Vector3 )
+ self.set( a.x+b.x, a.y+b.y, a.z+b.z )
+ return self
+
+
class _ObjectBase:
def add(self, child):
ob = self._object
@@ -190,9 +190,6 @@ def visit_ClassDef(self, node):
if self._catch_attributes:
self._inline_classes[ name ] = self._catch_attributes
- writer.write('#decorators#')
- writer.write('#%s' %self._decorator_properties)
- writer.write('#--------------------------------')
self._catch_attributes = None
self._decorator_properties = None
self._instances.pop('self')
@@ -428,8 +425,13 @@ def visit_Expr(self, node):
def visit_Call(self, node):
if hasattr(node.func, 'id') and node.func.id in ('JS', 'toString', 'JSObject', 'JSArray', 'var'):
args = list( map(self.visit, node.args) ) ## map in py3 returns an iterator not a list
- kwargs = map(lambda x: '%s=%s' % (x.arg, self.visit(x.value)), node.keywords)
- args.extend(kwargs)
+ if node.func.id == 'var':
+ for k in node.keywords:
+ self._instances[ k.arg ] = k.value.id
+ args.append( k.arg )
+ else:
+ kwargs = map(lambda x: '%s=%s' % (x.arg, self.visit(x.value)), node.keywords)
+ args.extend(kwargs)
args = ', '.join(args)
return '%s(%s)' % (node.func.id, args)
else:
@@ -28,6 +28,14 @@
print( v1.y )
print( v1.z )
+ v3 = Vector3(400,400,400)
+ v4 = Vector3()
+ v4.addScalar( 20 )
+ v1.addVectors( v3, v4 )
+ print( v1.x )
+ print( v1.y )
+ print( v1.z )
+
</script>
</head>

0 comments on commit 71d5664

Please sign in to comment.