Mercurial Hosting > luan
comparison src/luan/interp/ExpList.java @ 31:5cf15507d77e
separate interpreter from interface
git-svn-id: https://luan-java.googlecode.com/svn/trunk@32 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Thu, 13 Dec 2012 02:50:04 +0000 |
parents | 3b22ffbdb83a |
children | e3624b7cd603 |
comparison
equal
deleted
inserted
replaced
30:8d8f4f5caef4 | 31:5cf15507d77e |
---|---|
2 | 2 |
3 import java.util.List; | 3 import java.util.List; |
4 import java.util.ArrayList; | 4 import java.util.ArrayList; |
5 import java.util.Collections; | 5 import java.util.Collections; |
6 import luan.LuaException; | 6 import luan.LuaException; |
7 import luan.LuaState; | |
8 | 7 |
9 | 8 |
10 final class ExpList implements Expressions { | 9 final class ExpList implements Expressions { |
11 | 10 |
12 private interface Adder { | 11 private interface Adder { |
13 public void addTo(LuaState lua,List<Object> list) throws LuaException; | 12 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException; |
14 } | 13 } |
15 | 14 |
16 private static class ExprAdder implements Adder { | 15 private static class ExprAdder implements Adder { |
17 private final Expr expr; | 16 private final Expr expr; |
18 | 17 |
19 ExprAdder(Expr expr) { | 18 ExprAdder(Expr expr) { |
20 this.expr = expr; | 19 this.expr = expr; |
21 } | 20 } |
22 | 21 |
23 public void addTo(LuaState lua,List<Object> list) throws LuaException { | 22 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException { |
24 list.add( expr.eval(lua) ); | 23 list.add( expr.eval(lua) ); |
25 } | 24 } |
26 | 25 |
27 } | 26 } |
28 | 27 |
31 | 30 |
32 ExpressionsAdder(Expressions expressions) { | 31 ExpressionsAdder(Expressions expressions) { |
33 this.expressions = expressions; | 32 this.expressions = expressions; |
34 } | 33 } |
35 | 34 |
36 public void addTo(LuaState lua,List<Object> list) throws LuaException { | 35 public void addTo(LuaStateImpl lua,List<Object> list) throws LuaException { |
37 for( Object val : expressions.eval(lua) ) { | 36 for( Object val : expressions.eval(lua) ) { |
38 list.add( val ); | 37 list.add( val ); |
39 } | 38 } |
40 } | 39 } |
41 | 40 |
69 } | 68 } |
70 | 69 |
71 private static final Object[] EMPTY = new Object[0]; | 70 private static final Object[] EMPTY = new Object[0]; |
72 | 71 |
73 static final Expressions emptyExpList = new Expressions() { | 72 static final Expressions emptyExpList = new Expressions() { |
74 @Override public Object[] eval(LuaState lua) { | 73 @Override public Object[] eval(LuaStateImpl lua) { |
75 return EMPTY; | 74 return EMPTY; |
76 } | 75 } |
77 }; | 76 }; |
78 | 77 |
79 static class SingleExpList implements Expressions { | 78 static class SingleExpList implements Expressions { |
81 | 80 |
82 SingleExpList(Expr expr) { | 81 SingleExpList(Expr expr) { |
83 this.expr = expr; | 82 this.expr = expr; |
84 } | 83 } |
85 | 84 |
86 @Override public Object[] eval(LuaState lua) throws LuaException { | 85 @Override public Object[] eval(LuaStateImpl lua) throws LuaException { |
87 return new Object[]{expr.eval(lua)}; | 86 return new Object[]{expr.eval(lua)}; |
88 } | 87 } |
89 } | 88 } |
90 | 89 |
91 private final Adder[] adders; | 90 private final Adder[] adders; |
92 | 91 |
93 private ExpList(Adder[] adders) { | 92 private ExpList(Adder[] adders) { |
94 this.adders = adders; | 93 this.adders = adders; |
95 } | 94 } |
96 | 95 |
97 @Override public Object[] eval(LuaState lua) throws LuaException { | 96 @Override public Object[] eval(LuaStateImpl lua) throws LuaException { |
98 List<Object> list = new ArrayList<Object>(); | 97 List<Object> list = new ArrayList<Object>(); |
99 for( Adder adder : adders ) { | 98 for( Adder adder : adders ) { |
100 adder.addTo(lua,list); | 99 adder.addTo(lua,list); |
101 } | 100 } |
102 return list.toArray(); | 101 return list.toArray(); |