comparison core/src/luan/impl/$Luan.java @ 648:e387e4021afe

start compiler with len operator
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 30 Mar 2016 19:40:48 -0600
parents
children 37f0cf43f191
comparison
equal deleted inserted replaced
647:8e8c30b72e9b 648:e387e4021afe
1 package luan.impl;
2
3 import java.util.List;
4 import java.util.ArrayList;
5 import luan.Luan;
6 import luan.LuanTable;
7 import luan.LuanException;
8
9
10 public final class $Luan {
11 private $Luan() {} // never
12
13
14 private static List<Expressions> listExpressions = new ArrayList<Expressions>();
15
16 static int addExpressions(Expressions exp) {
17 int i = listExpressions.size();
18 listExpressions.add(exp);
19 return i;
20 }
21
22 public static Expressions getExpressions(int i) {
23 return listExpressions.get(i);
24 }
25
26
27 public static Object first(Object obj) {
28 return Luan.first(obj);
29 }
30
31 public static int len(LuanStateImpl luan,Object o) throws LuanException {
32 if( o instanceof String ) {
33 String s = (String)o;
34 return s.length();
35 }
36 if( o instanceof byte[] ) {
37 byte[] a = (byte[])o;
38 return a.length;
39 }
40 if( o instanceof LuanTable ) {
41 LuanTable t = (LuanTable)o;
42 return t.length(luan);
43 }
44 throw new LuanException( "attempt to get length of a " + Luan.type(o) + " value" );
45 }
46 }