Mercurial Hosting > luan
diff src/luan/Luan.java @ 111:2428ecfed375
change LuanFunction.call() from returning Object[] to returning Object, to reduce garbage collection
git-svn-id: https://luan-java.googlecode.com/svn/trunk@112 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 23 May 2014 20:40:05 +0000 |
parents | a9560839104d |
children | 8c706d6eb5dc |
line wrap: on
line diff
--- a/src/luan/Luan.java Fri May 23 04:36:47 2014 +0000 +++ b/src/luan/Luan.java Fri May 23 20:40:05 2014 +0000 @@ -4,6 +4,17 @@ public final class Luan { public static final String version = "Luan 0.1"; + public static Object first(Object obj) { + if( !(obj instanceof Object[]) ) + return obj; + Object[] a = (Object[])obj; + return a.length==0 ? null : a[0]; + } + + public static Object[] array(Object obj) { + return obj instanceof Object[] ? (Object[])obj : new Object[]{obj}; + } + public static String type(Object obj) { if( obj == null ) return "nil"; @@ -51,10 +62,6 @@ return null; } - public static Object first(Object[] a) { - return a.length==0 ? null : a[0]; - } - public static String toString(Number n) { if( n instanceof Integer ) return n.toString();