Mercurial Hosting > luan
comparison src/luan/LuanState.java @ 1166:7ef40e1923b7
add back Thread.global
allow metatables to have metatables
| author | Franklin Schmidt <fschmidt@gmail.com> |
|---|---|
| date | Thu, 08 Feb 2018 02:22:51 -0700 |
| parents | ba4daf107e07 |
| children | d3a3ca116e42 |
comparison
equal
deleted
inserted
replaced
| 1165:668f29bc52ea | 1166:7ef40e1923b7 |
|---|---|
| 94 if( obj instanceof Number ) | 94 if( obj instanceof Number ) |
| 95 return (Number)obj; | 95 return (Number)obj; |
| 96 throw new LuanException( "attempt to perform arithmetic on '"+context()+"' (a " + Luan.type(obj) + " value)" ); | 96 throw new LuanException( "attempt to perform arithmetic on '"+context()+"' (a " + Luan.type(obj) + " value)" ); |
| 97 } | 97 } |
| 98 */ | 98 */ |
| 99 | |
| 100 | |
| 101 public boolean isLessThan(Object o1,Object o2) throws LuanException { | |
| 102 if( o1 instanceof Number && o2 instanceof Number ) { | |
| 103 Number n1 = (Number)o1; | |
| 104 Number n2 = (Number)o2; | |
| 105 return n1.doubleValue() < n2.doubleValue(); | |
| 106 } | |
| 107 if( o1 instanceof String && o2 instanceof String ) { | |
| 108 String s1 = (String)o1; | |
| 109 String s2 = (String)o2; | |
| 110 return s1.compareTo(s2) < 0; | |
| 111 } | |
| 112 LuanFunction fn = getBinHandler("__lt",o1,o2); | |
| 113 if( fn != null ) | |
| 114 return Luan.checkBoolean( Luan.first(fn.call(this,new Object[]{o1,o2})) ); | |
| 115 throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); | |
| 116 } | |
| 117 | |
| 118 public LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException { | |
| 119 if( o1 instanceof LuanTable ) { | |
| 120 LuanFunction f1 = getHandlerFunction(op,(LuanTable)o1); | |
| 121 if( f1 != null ) | |
| 122 return f1; | |
| 123 } | |
| 124 return o2 instanceof LuanTable ? getHandlerFunction(op,(LuanTable)o2) : null; | |
| 125 } | |
| 126 | |
| 127 public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException { | |
| 128 Object f = t.getHandler(this,op); | |
| 129 if( f == null ) | |
| 130 return null; | |
| 131 return Luan.checkFunction(f); | |
| 132 } | |
| 99 } | 133 } |
