Skip to content

Commit bd92ecc

Browse files
author
hartsantler
committed
small fixes
1 parent 21ee145 commit bd92ecc

5 files changed

Lines changed: 40 additions & 22 deletions

File tree

pythonjs.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// PythonJS Runtime - regenerated on: Thu Feb 6 23:40:16 2014
1+
// PythonJS Runtime - regenerated on: Sat Feb 8 20:59:42 2014
22
__NULL_OBJECT__ = Object.create(null);
33
if (( "window" ) in this && ( "document" ) in this) {
44
__WEBWORKER__ = false;
@@ -432,6 +432,18 @@ __contains__.NAME = "__contains__";
432432
__contains__.args_signature = ["ob", "a"];
433433
__contains__.kwargs_signature = { };
434434
__contains__.types_signature = { };
435+
__split_method = function(ob) {
436+
if (( typeof(ob) ) == "string") {
437+
return ob.split(" ");
438+
} else {
439+
return __split_method(ob);
440+
}
441+
}
442+
443+
__split_method.NAME = "__split_method";
444+
__split_method.args_signature = ["ob"];
445+
__split_method.kwargs_signature = { };
446+
__split_method.types_signature = { };
435447
__test_if_true__ = function(ob) {
436448
if (! (ob)) {
437449
return false;

pythonjs/python_to_pythonjs.py

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1684,6 +1684,9 @@ def visit_Call(self, node):
16841684
else:
16851685
return '__jsdict_pop(%s)' %self.visit(anode.value)
16861686

1687+
elif anode.attr == 'split' and not args:
1688+
return '__split_method(%s)' %self.visit(anode.value)
1689+
16871690
else:
16881691
a = ','.join(args)
16891692
if node.keywords:
@@ -1722,8 +1725,6 @@ def visit_Call(self, node):
17221725
else:
17231726
return '%s(%s)' %( self.visit(node.func), ','.join(args) )
17241727

1725-
#a = ','.join(args)
1726-
#return '%s(%s)' %( self.visit(node.func), a )
17271728

17281729
elif isinstance(node.func, Name) and node.func.id in self._generator_functions:
17291730
name = self.visit(node.func)
@@ -1788,13 +1789,6 @@ def visit_Call(self, node):
17881789
writer.append('var(%s, %s)' % (args_name, kwargs_name))
17891790
self.identifier += 1
17901791

1791-
#if name in ('list', 'tuple'):
1792-
# if args:
1793-
# writer.append( '%s = %s[...]' % (args_name, args)) ## test this
1794-
# else:
1795-
# writer.append( '%s = []' %args_name )
1796-
#else:
1797-
# writer.append('%s = JSArray(%s)' % (args_name, args))
17981792
writer.append('%s = [%s]' % (args_name, args))
17991793

18001794
if node.starargs:
@@ -1813,18 +1807,8 @@ def visit_Call(self, node):
18131807

18141808
#######################################
18151809

1816-
#if name in self._func_typedefs:
1817-
# if args and kwargs:
1818-
# return '%s(%s, %s)' %(args_name, kwargs_name)
1819-
# elif args:
1820-
# return '%s(%s, {})' %args_name
1821-
# elif kwargs:
1822-
# return '%s([], %s)' %kwargs_name
1823-
# else:
1824-
# return '%s()' %name
1825-
18261810
## special method calls ##
1827-
if isinstance(node.func, ast.Attribute) and node.func.attr in ('get', 'keys', 'values', 'pop', 'items') and not self._with_lua:
1811+
if isinstance(node.func, ast.Attribute) and node.func.attr in ('get', 'keys', 'values', 'pop', 'items', 'split') and not self._with_lua:
18281812
anode = node.func
18291813
if anode.attr == 'get':
18301814
if args:
@@ -1847,6 +1831,9 @@ def visit_Call(self, node):
18471831
else:
18481832
return '__jsdict_pop(%s)' %self.visit(anode.value)
18491833

1834+
elif anode.attr == 'split' and not args:
1835+
return '__split_method(%s)' %self.visit(anode.value)
1836+
18501837
else:
18511838
return '%s(%s)' %( self.visit(node.func), args )
18521839

pythonjs/pythonjs_to_lua.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ def visit_And(self, node):
5252
def visit_Or(self, node):
5353
return ' or '
5454

55+
def visit_Not(self, node):
56+
return ' not '
57+
5558

5659
def visit_Subscript(self, node):
5760
if isinstance(node.slice, ast.Ellipsis):
@@ -282,10 +285,14 @@ def visit_TryExcept(self, node):
282285
self.push()
283286
for n in node.handlers:
284287
out.append( self.indent() + self.visit(n) )
285-
self.pull()
286288
out.append( self.indent() + 'end' )
289+
self.pull()
287290
return '\n'.join( out )
288291

292+
def visit_ExceptHandler(self, node):
293+
## TODO check exception
294+
return '--exception: %s' %self.visit(node.type)
295+
289296
def main(script):
290297
tree = ast.parse(script)
291298
return LuaGenerator().visit(tree)

runtime/builtins.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ def __contains__( ob, a ):
3838
elif typeof(a)=='string' and Object.hasOwnProperty.call(ob, a):
3939
return True
4040

41+
def __split_method( ob ):
42+
## special case because calling string.split() without args its not the same as python,
43+
## and we do not want to touch the default string.split implementation.
44+
if typeof(ob) == 'string':
45+
return ob.split(' ')
46+
else:
47+
return ob.split()
48+
4149
def __test_if_true__( ob ):
4250
if not ob:
4351
return False

runtime/lua_builtins.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,10 @@ def ord(a):
201201
with lowlevel:
202202
return string.byte(a)
203203

204+
def getattr(ob, name):
205+
with lowlevel:
206+
return ob[name] ## could be None (nil), no good way to raise AttributeError
207+
204208
class __iterator_string:
205209
def __init__(self, obj, index):
206210
with lowlevel:

0 commit comments

Comments
 (0)