Mercurial Hosting > luan
comparison src/luan/LuanBit.java @ 112:f5af13062b10
fix previous rev
git-svn-id: https://luan-java.googlecode.com/svn/trunk@113 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 23 May 2014 22:52:39 +0000 |
parents | 2428ecfed375 |
children | d7be9b3abf1a |
comparison
equal
deleted
inserted
replaced
111:2428ecfed375 | 112:f5af13062b10 |
---|---|
14 | 14 |
15 public LuanException exception(Object msg) { | 15 public LuanException exception(Object msg) { |
16 return new LuanException(this,msg); | 16 return new LuanException(this,msg); |
17 } | 17 } |
18 | 18 |
19 public Object call(LuanFunction fn,String fnName,Object... args) throws LuanException { | 19 public Object call(LuanFunction fn,String fnName) throws LuanException { |
20 return call(fn,fnName,LuanFunction.EMPTY); | |
21 } | |
22 | |
23 public Object call(LuanFunction fn,String fnName,Object[] args) throws LuanException { | |
20 List<StackTraceElement> stackTrace = luan.stackTrace; | 24 List<StackTraceElement> stackTrace = luan.stackTrace; |
21 stackTrace.add( new StackTraceElement(el,fnName) ); | 25 stackTrace.add( new StackTraceElement(el,fnName) ); |
22 try { | 26 try { |
23 return fn.call(luan,args); | 27 return fn.call(luan,args); |
24 } finally { | 28 } finally { |
47 } | 51 } |
48 | 52 |
49 public String toString(Object obj) throws LuanException { | 53 public String toString(Object obj) throws LuanException { |
50 LuanFunction fn = getHandlerFunction("__tostring",obj); | 54 LuanFunction fn = getHandlerFunction("__tostring",obj); |
51 if( fn != null ) | 55 if( fn != null ) |
52 return checkString( Luan.first( call(fn,"__tostring",obj) ) ); | 56 return checkString( Luan.first( call(fn,"__tostring",new Object[]{obj}) ) ); |
53 return Luan.toString(obj); | 57 return Luan.toString(obj); |
54 } | 58 } |
55 | 59 |
56 public String repr(Object obj) throws LuanException { | 60 public String repr(Object obj) throws LuanException { |
57 LuanFunction fn = getHandlerFunction("__repr",obj); | 61 LuanFunction fn = getHandlerFunction("__repr",obj); |
58 if( fn != null ) | 62 if( fn != null ) |
59 return checkString( Luan.first( call(fn,"__repr",obj) ) ); | 63 return checkString( Luan.first( call(fn,"__repr",new Object[]{obj}) ) ); |
60 String repr = Luan.repr(obj); | 64 String repr = Luan.repr(obj); |
61 if( repr==null ) | 65 if( repr==null ) |
62 throw exception( "value '" + obj + "' doesn't support repr()" ); | 66 throw exception( "value '" + obj + "' doesn't support repr()" ); |
63 return repr; | 67 return repr; |
64 } | 68 } |
88 String s2 = (String)o2; | 92 String s2 = (String)o2; |
89 return s1.compareTo(s2) < 0; | 93 return s1.compareTo(s2) < 0; |
90 } | 94 } |
91 LuanFunction fn = getBinHandler("__lt",o1,o2); | 95 LuanFunction fn = getBinHandler("__lt",o1,o2); |
92 if( fn != null ) | 96 if( fn != null ) |
93 return Luan.toBoolean( Luan.first(call(fn,"__lt",o1,o2)) ); | 97 return Luan.toBoolean( Luan.first(call(fn,"__lt",new Object[]{o1,o2})) ); |
94 throw exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); | 98 throw exception( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); |
95 } | 99 } |
96 | 100 |
97 public Object arithmetic(String op,Object o1,Object o2) throws LuanException { | 101 public Object arithmetic(String op,Object o1,Object o2) throws LuanException { |
98 LuanFunction fn = getBinHandler(op,o1,o2); | 102 LuanFunction fn = getBinHandler(op,o1,o2); |
99 if( fn != null ) | 103 if( fn != null ) |
100 return Luan.first(call(fn,op,o1,o2)); | 104 return Luan.first(call(fn,op,new Object[]{o1,o2})); |
101 String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2); | 105 String type = Luan.toNumber(o1)==null ? Luan.type(o1) : Luan.type(o2); |
102 throw exception("attempt to perform arithmetic on a "+type+" value"); | 106 throw exception("attempt to perform arithmetic on a "+type+" value"); |
103 } | 107 } |
104 | 108 |
105 } | 109 } |