Commits

masklinn committed 1758bfe

Implement conversion of Array to py.list and tuple/list.__getitem__ (very basic)

Comments (0)

Files changed (2)

                 }
             }
             return o;
+        case Array:
+            var a = new py.list();
+            a.values = val;
+            return a;
         }
 
         throw new Error("Could not convert " + val + " to a pyval");
             }
             return py.False;
         },
+        __getitem__: function (index) {
+            return PY_ensurepy(this.values[index.toJSON()]);
+        },
         toJSON: function () {
             var out = [];
             for (var i=0; i<this.values.length; ++i) {
         case '[':
             if (expr.second) {
                 return py.evaluate(expr.first, context)
-                    .__getitem__(expr.evaluate(expr.second, context));
+                    .__getitem__(py.evaluate(expr.second, context));
             }
             var list_exprs = expr.first, list_values = [];
             for (var k=0; k<list_exprs.length; ++k) {
     it('should convert bare objects to objects', function () {
         expect(py.eval('foo.bar', {foo: {bar: 3}})).to.be(3);
     });
+    it('should convert arrays to lists', function () {
+        expect(py.eval('foo[3]', {foo: [9, 8, 7, 6, 5]}))
+            .to.be(6);
+    });
 });