Mercurial Hosting > luan
diff core/src/luan/LuanState.java @ 579:f22a09e98b04
clean up LuanState
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 16 Jul 2015 15:14:31 -0600 |
parents | 60c549d43988 |
children | 859c0dedc8b6 |
line wrap: on
line diff
--- a/core/src/luan/LuanState.java Tue Jul 14 17:40:48 2015 -0600 +++ b/core/src/luan/LuanState.java Thu Jul 16 15:14:31 2015 -0600 @@ -15,7 +15,7 @@ public abstract class LuanState implements DeepCloneable { - final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); + protected final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); private Map registry; private final List<Reference<Closeable>> onClose = new ArrayList<Reference<Closeable>>(); @@ -71,15 +71,6 @@ throw new LuanException(this, "attempt to use '"+context()+"' (a " + Luan.type(obj) + " value) as a boolean" ); } - public Boolean checkBoolean(Object obj,LuanElement el) throws LuanException { - push(el,null); - try { - return checkBoolean(obj); - } finally { - pop(); - } - } - public String checkString(Object obj) throws LuanException { if( obj instanceof String ) return (String)obj; @@ -92,22 +83,7 @@ throw new LuanException(this, "attempt to call '"+context()+"' (a " + Luan.type(obj) + " value)" ); } - public boolean isLessThan(Object o1,Object o2) throws LuanException { - if( o1 instanceof Number && o2 instanceof Number ) { - Number n1 = (Number)o1; - Number n2 = (Number)o2; - return n1.doubleValue() < n2.doubleValue(); - } - if( o1 instanceof String && o2 instanceof String ) { - String s1 = (String)o1; - String s2 = (String)o2; - return s1.compareTo(s2) < 0; - } - LuanFunction fn = getBinHandler("__lt",o1,o2); - if( fn != null ) - return checkBoolean( Luan.first(fn.call(this,new Object[]{o1,o2})) ); - throw new LuanException(this, "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); - } + abstract public boolean isLessThan(Object o1,Object o2) throws LuanException; public String toString(Object obj) throws LuanException { if( obj instanceof LuanTable ) { @@ -123,15 +99,6 @@ return obj.toString(); } - public String toString(Object obj,LuanElement el) throws LuanException { - push(el,null); - try { - return toString(obj); - } finally { - pop(); - } - } - public Object index(Object obj,Object key) throws LuanException { if( obj instanceof LuanTable ) { LuanTable tbl = (LuanTable)obj; @@ -146,31 +113,6 @@ return stackTrace.get(stackTrace.size()-1).call.text(); } - public void push(LuanElement el,String fnName) { - if( el == null ) throw new RuntimeException(); - stackTrace.add( new StackTraceElement(el,fnName) ); - } - - public void pop() { - stackTrace.remove(stackTrace.size()-1); - } - - public LuanFunction getBinHandler(String op,Object o1,Object o2) throws LuanException { - if( o1 instanceof LuanTable ) { - LuanFunction f1 = getHandlerFunction(op,(LuanTable)o1); - if( f1 != null ) - return f1; - } - return o2 instanceof LuanTable ? getHandlerFunction(op,(LuanTable)o2) : null; - } - - public LuanFunction getHandlerFunction(String op,LuanTable t) throws LuanException { - Object f = t.getHandler(op); - if( f == null ) - return null; - return checkFunction(f); - } - public void dumpStack() { System.err.println( stackTrace ); }