Skip to content

Commit

Permalink
[python] Fix python vector syntax issue (#11060)
Browse files Browse the repository at this point in the history
* [python] Wrap vector in brackets

Avoid error with inline vector index expression

* Add missing semicolon

* [tests] Add tests for python inlined vectors
  • Loading branch information
tobil4sk authored Mar 30, 2023
1 parent 341371d commit 6818afe
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
6 changes: 3 additions & 3 deletions std/haxe/ds/Vector.hx
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private typedef VectorData<T> =
eval.Vector<T>
#else
Array<T>
#end
#end;

/**
A Vector is a storage of fixed size. It can be faster than Array on some
Expand Down Expand Up @@ -75,7 +75,7 @@ abstract Vector<T>(VectorData<T>) {
#elseif cpp
this = NativeArray.create(length);
#elseif python
this = python.Syntax.code("[{0}]*{1}", null, length);
this = python.Syntax.code("([{0}]*{1})", null, length);
#elseif lua
this = untyped __lua_table__({length: length});
#elseif eval
Expand All @@ -97,7 +97,7 @@ abstract Vector<T>(VectorData<T>) {
#if js
this = [for (_ in 0...length) defaultValue];
#elseif python
this = python.Syntax.code("[{0}]*{1}", defaultValue, length);
this = python.Syntax.code("([{0}]*{1})", defaultValue, length);
#else

#if flash10
Expand Down
3 changes: 3 additions & 0 deletions tests/misc/python/projects/Issue11060/Main.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
function main() {
trace(new haxe.ds.Vector(1)[0]);
}
3 changes: 3 additions & 0 deletions tests/misc/python/projects/Issue11060/build.hxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-python bin/main.py
--main Main
-cmd python3 bin/main.py
1 change: 1 addition & 0 deletions tests/misc/python/projects/Issue11060/build.hxml.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
None

0 comments on commit 6818afe

Please sign in to comment.