Mercurial Hosting > luan
comparison 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 |
comparison
equal
deleted
inserted
replaced
110:7afa6df829f3 | 111:2428ecfed375 |
---|---|
1 package luan; | 1 package luan; |
2 | 2 |
3 | 3 |
4 public final class Luan { | 4 public final class Luan { |
5 public static final String version = "Luan 0.1"; | 5 public static final String version = "Luan 0.1"; |
6 | |
7 public static Object first(Object obj) { | |
8 if( !(obj instanceof Object[]) ) | |
9 return obj; | |
10 Object[] a = (Object[])obj; | |
11 return a.length==0 ? null : a[0]; | |
12 } | |
13 | |
14 public static Object[] array(Object obj) { | |
15 return obj instanceof Object[] ? (Object[])obj : new Object[]{obj}; | |
16 } | |
6 | 17 |
7 public static String type(Object obj) { | 18 public static String type(Object obj) { |
8 if( obj == null ) | 19 if( obj == null ) |
9 return "nil"; | 20 return "nil"; |
10 if( obj instanceof String ) | 21 if( obj instanceof String ) |
47 else | 58 else |
48 return Long.valueOf(s,base); | 59 return Long.valueOf(s,base); |
49 } catch(NumberFormatException e) {} | 60 } catch(NumberFormatException e) {} |
50 } | 61 } |
51 return null; | 62 return null; |
52 } | |
53 | |
54 public static Object first(Object[] a) { | |
55 return a.length==0 ? null : a[0]; | |
56 } | 63 } |
57 | 64 |
58 public static String toString(Number n) { | 65 public static String toString(Number n) { |
59 if( n instanceof Integer ) | 66 if( n instanceof Integer ) |
60 return n.toString(); | 67 return n.toString(); |