Mercurial Hosting > luan
comparison src/luan/Luan.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 | 1f9d34a6f308 |
children | ce3279ef1bd9 |
comparison
equal
deleted
inserted
replaced
1165:668f29bc52ea | 1166:7ef40e1923b7 |
---|---|
112 if( obj instanceof LuanFunction ) | 112 if( obj instanceof LuanFunction ) |
113 return (LuanFunction)obj; | 113 return (LuanFunction)obj; |
114 throw new LuanException("attempt to call a " + Luan.type(obj) + " value" ); | 114 throw new LuanException("attempt to call a " + Luan.type(obj) + " value" ); |
115 } | 115 } |
116 | 116 |
117 public static boolean isLessThan(LuanState luan,Object o1,Object o2) throws LuanException { | |
118 if( o1 instanceof Number && o2 instanceof Number ) { | |
119 Number n1 = (Number)o1; | |
120 Number n2 = (Number)o2; | |
121 return n1.doubleValue() < n2.doubleValue(); | |
122 } | |
123 if( o1 instanceof String && o2 instanceof String ) { | |
124 String s1 = (String)o1; | |
125 String s2 = (String)o2; | |
126 return s1.compareTo(s2) < 0; | |
127 } | |
128 LuanFunction fn = getBinHandler("__lt",o1,o2); | |
129 if( fn != null ) | |
130 return checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); | |
131 throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); | |
132 } | |
133 | |
134 public static LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException { | |
135 if( o1 instanceof LuanTable ) { | |
136 LuanFunction f1 = getHandlerFunction(op,(LuanTable)o1); | |
137 if( f1 != null ) | |
138 return f1; | |
139 } | |
140 return o2 instanceof LuanTable ? getHandlerFunction(op,(LuanTable)o2) : null; | |
141 } | |
142 | |
143 public static LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException { | |
144 Object f = t.getHandler(op); | |
145 if( f == null ) | |
146 return null; | |
147 return checkFunction(f); | |
148 } | |
149 | |
150 public static LuanFunction load(String text,String sourceName,LuanTable env) | 117 public static LuanFunction load(String text,String sourceName,LuanTable env) |
151 throws LuanException | 118 throws LuanException |
152 { | 119 { |
153 return LuanCompiler.compile(text,sourceName,env); | 120 return LuanCompiler.compile(text,sourceName,env); |
154 } | 121 } |