1. Brian Leibig
  2. snakes-on-a-moon

Commits

Brian Leibig  committed 1bb15d0

Fixes for LuaTable and tonumber

  • Participants
  • Parent commits f3d4416
  • Branches default

Comments (0)

Files changed (3)

File interpreter.py

View file
  • Ignore whitespace
                 assert isinstance(reg, LuaValue)
             for upv in self.upvalues:
                 assert isinstance(upv, LuaValue)
-            for g in self.globals:
+            for g in self.globals.array:
+                assert not isinstance(g, LuaValue)
+            for g in self.globals.hash:
                 assert not isinstance(g, LuaValue)
 
     @staticmethod

File library.py

View file
  • Ignore whitespace
 def lua_tonumber(args):
     e = args[0]
     base = args[1] if len(args) > 1 else 10
-    return [int(e, base)]
+    result = 0
+    try:
+        result = int(str(e), base)
+    except ValueError:
+        result = None
+    return [result]
 
 def lua_tostring(args):
     e = args[0]

File luatypes.py

View file
  • Ignore whitespace
     def __getitem__(self, key):
         if isinstance(key, (int, long, float)) and int(key) == key and key > 0:
             key = int(key)
-            return self.array[key-1] if len(self.array) >= key-1 else None
+            return self.array[key-1] if len(self.array) >= key else None
         else:
             return self.hash[key] if key in self.hash else None