Mercurial Hosting > luan
diff src/luan/impl/LuanImpl.java @ 1333:25746915a241
merge Luan and LuanState
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 12 Feb 2019 22:33:40 -0700 |
parents | f41919741100 |
children | c88b486a9511 |
line wrap: on
line diff
--- a/src/luan/impl/LuanImpl.java Tue Feb 12 21:50:26 2019 -0700 +++ b/src/luan/impl/LuanImpl.java Tue Feb 12 22:33:40 2019 -0700 @@ -4,7 +4,6 @@ import java.util.List; import java.util.ArrayList; import luan.Luan; -import luan.LuanState; import luan.LuanTable; import luan.LuanFunction; import luan.LuanException; @@ -30,7 +29,7 @@ throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" ); } - public static Object unm(LuanState luan,Object o) throws LuanException { + public static Object unm(Luan luan,Object o) throws LuanException { if( o instanceof Number ) return -((Number)o).doubleValue(); if( o instanceof LuanTable ) { @@ -42,7 +41,7 @@ throw new LuanException("attempt to perform arithmetic on a "+Luan.type(o)+" value"); } - private static Object arithmetic(LuanState luan,String op,Object o1,Object o2) throws LuanException { + private static Object arithmetic(Luan luan,String op,Object o1,Object o2) throws LuanException { LuanFunction fn = luan.getBinHandler(op,o1,o2); if( fn != null ) return Luan.first(fn.call(luan,new Object[]{o1,o2})); @@ -50,25 +49,25 @@ throw new LuanException("attempt to perform arithmetic on a "+type+" value"); } - public static Object pow(LuanState luan,Object o1,Object o2) throws LuanException { + public static Object pow(Luan luan,Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return Math.pow( ((Number)o1).doubleValue(), ((Number)o2).doubleValue() ); return arithmetic(luan,"__pow",o1,o2); } - public static Object mul(LuanState luan,Object o1,Object o2) throws LuanException { + public static Object mul(Luan luan,Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() * ((Number)o2).doubleValue(); return arithmetic(luan,"__mul",o1,o2); } - public static Object div(LuanState luan,Object o1,Object o2) throws LuanException { + public static Object div(Luan luan,Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() / ((Number)o2).doubleValue(); return arithmetic(luan,"__div",o1,o2); } - public static Object mod(LuanState luan,Object o1,Object o2) throws LuanException { + public static Object mod(Luan luan,Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) { double d1 = ((Number)o1).doubleValue(); double d2 = ((Number)o2).doubleValue(); @@ -77,19 +76,19 @@ return arithmetic(luan,"__mod",o1,o2); } - public static Object add(LuanState luan,Object o1,Object o2) throws LuanException { + public static Object add(Luan luan,Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() + ((Number)o2).doubleValue(); return arithmetic(luan,"__add",o1,o2); } - public static Object sub(LuanState luan,Object o1,Object o2) throws LuanException { + public static Object sub(Luan luan,Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) return ((Number)o1).doubleValue() - ((Number)o2).doubleValue(); return arithmetic(luan,"__sub",o1,o2); } - public static Object concat(LuanState luan,Object o1,Object o2) throws LuanException { + public static Object concat(Luan luan,Object o1,Object o2) throws LuanException { LuanFunction fn = luan.getBinHandler("__concat",o1,o2); if( fn != null ) return Luan.first(fn.call(luan,new Object[]{o1,o2})); @@ -98,7 +97,7 @@ return s1 + s2; } - public static boolean eq(LuanState luan,Object o1,Object o2) throws LuanException { + public static boolean eq(Luan luan,Object o1,Object o2) throws LuanException { if( o1 == o2 || o1 != null && o1.equals(o2) ) return true; if( o1 instanceof Number && o2 instanceof Number ) { @@ -126,7 +125,7 @@ return Luan.checkBoolean( Luan.first(fn.call(luan,new Object[]{o1,o2})) ); } - public static boolean le(LuanState luan,Object o1,Object o2) throws LuanException { + public static boolean le(Luan luan,Object o1,Object o2) throws LuanException { if( o1 instanceof Number && o2 instanceof Number ) { Number n1 = (Number)o1; Number n2 = (Number)o2; @@ -146,7 +145,7 @@ throw new LuanException( "attempt to compare " + Luan.type(o1) + " with " + Luan.type(o2) ); } - public static boolean lt(LuanState luan,Object o1,Object o2) throws LuanException { + public static boolean lt(Luan luan,Object o1,Object o2) throws LuanException { return luan.isLessThan(o1,o2); } @@ -156,7 +155,7 @@ public static void nop(Object o) {} - public static void put(LuanState luan,Object t,Object key,Object value) throws LuanException { + public static void put(Luan luan,Object t,Object key,Object value) throws LuanException { if( t instanceof LuanTable ) { LuanTable tbl = (LuanTable)t; tbl.put(key,value); @@ -229,7 +228,7 @@ } } - public static LuanTable table(LuanState luan,Object[] a) throws LuanException { + public static LuanTable table(Luan luan,Object[] a) throws LuanException { LuanTable table = new LuanTable(luan); int i = 0; for( Object fld : a ) {