Skip to content

Commit 71d5664

Browse files
author
hartsantler
committed
added new style to declare the type of a variable using the special function: var(x=SomeType)
1 parent b772e3b commit 71d5664

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

bindings/three.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,16 @@ def add(self, other):
6464
self.set( self.x+other.x, self.y+other.y, self.z+other.z )
6565
return self
6666

67+
def addScalar(self, s):
68+
self.set( self.x+s, self.y+s, self.z+s )
69+
return self
70+
71+
def addVectors(self, a,b):
72+
var( a=Vector3, b=Vector3 )
73+
self.set( a.x+b.x, a.y+b.y, a.z+b.z )
74+
return self
75+
76+
6777
class _ObjectBase:
6878
def add(self, child):
6979
ob = self._object

pythonscript/python_to_pythonjs.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,6 @@ def visit_ClassDef(self, node):
190190
if self._catch_attributes:
191191
self._inline_classes[ name ] = self._catch_attributes
192192

193-
writer.write('#decorators#')
194-
writer.write('#%s' %self._decorator_properties)
195-
writer.write('#--------------------------------')
196193
self._catch_attributes = None
197194
self._decorator_properties = None
198195
self._instances.pop('self')
@@ -428,8 +425,13 @@ def visit_Expr(self, node):
428425
def visit_Call(self, node):
429426
if hasattr(node.func, 'id') and node.func.id in ('JS', 'toString', 'JSObject', 'JSArray', 'var'):
430427
args = list( map(self.visit, node.args) ) ## map in py3 returns an iterator not a list
431-
kwargs = map(lambda x: '%s=%s' % (x.arg, self.visit(x.value)), node.keywords)
432-
args.extend(kwargs)
428+
if node.func.id == 'var':
429+
for k in node.keywords:
430+
self._instances[ k.arg ] = k.value.id
431+
args.append( k.arg )
432+
else:
433+
kwargs = map(lambda x: '%s=%s' % (x.arg, self.visit(x.value)), node.keywords)
434+
args.extend(kwargs)
433435
args = ', '.join(args)
434436
return '%s(%s)' % (node.func.id, args)
435437
else:

tests/threejs_vector3.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@
2828
print( v1.y )
2929
print( v1.z )
3030

31+
v3 = Vector3(400,400,400)
32+
v4 = Vector3()
33+
v4.addScalar( 20 )
34+
v1.addVectors( v3, v4 )
35+
print( v1.x )
36+
print( v1.y )
37+
print( v1.z )
38+
3139
</script>
3240
</head>
3341

0 commit comments

Comments
 (0)