Mercurial Hosting > luan
comparison core/src/luan/LuanState.java @ 575:7c3ad6db8ac3
make LuanState.JAVA private
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 13 Jul 2015 18:34:31 -0600 |
parents | 6cc2f047019b |
children | 4723d22062ce |
comparison
equal
deleted
inserted
replaced
574:6cc2f047019b | 575:7c3ad6db8ac3 |
---|---|
8 import java.util.ArrayList; | 8 import java.util.ArrayList; |
9 import java.util.Map; | 9 import java.util.Map; |
10 import java.util.HashMap; | 10 import java.util.HashMap; |
11 import luan.impl.LuanCompiler; | 11 import luan.impl.LuanCompiler; |
12 import luan.modules.BasicLuan; | 12 import luan.modules.BasicLuan; |
13 import luan.modules.JavaLuan; | |
13 | 14 |
14 | 15 |
15 public abstract class LuanState implements DeepCloneable { | 16 public abstract class LuanState implements DeepCloneable { |
16 | 17 |
17 final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); | 18 final List<StackTraceElement> stackTrace = new ArrayList<StackTraceElement>(); |
67 return new LuanBit(this,el); | 68 return new LuanBit(this,el); |
68 } | 69 } |
69 | 70 |
70 // convenience methods | 71 // convenience methods |
71 | 72 |
72 public final LuanBit JAVA = bit(null); | 73 private final LuanBit JAVA = bit(null); |
73 | 74 |
74 public LuanException exception(Object msg) throws LuanException { | 75 public LuanException exception(Object msg) throws LuanException { |
75 return JAVA.exception(msg); | 76 return JAVA.exception(msg); |
76 } | 77 } |
77 | 78 |
88 } | 89 } |
89 | 90 |
90 public boolean isLessThan(Object o1,Object o2) throws LuanException { | 91 public boolean isLessThan(Object o1,Object o2) throws LuanException { |
91 return JAVA.isLessThan(o1,o2); | 92 return JAVA.isLessThan(o1,o2); |
92 } | 93 } |
94 | |
95 public String toString(Object obj) throws LuanException { | |
96 if( obj instanceof LuanTable ) { | |
97 LuanTable tbl = (LuanTable)obj; | |
98 return tbl.toString(this); | |
99 } | |
100 if( obj == null ) | |
101 return "nil"; | |
102 if( obj instanceof Number ) | |
103 return Luan.toString((Number)obj); | |
104 if( obj instanceof byte[] ) | |
105 return "binary: " + Integer.toHexString(obj.hashCode()); | |
106 return obj.toString(); | |
107 } | |
108 | |
109 public Object index(Object obj,Object key) throws LuanException { | |
110 if( obj instanceof LuanTable ) { | |
111 LuanTable tbl = (LuanTable)obj; | |
112 return tbl.get(this,key); | |
113 } | |
114 if( obj != null && hasJava() ) | |
115 return JavaLuan.__index(this,obj,key,false); | |
116 throw exception( "attempt to index a " + Luan.type(obj) + " value in '"+context()+"'" ); | |
117 } | |
118 | |
119 public String context() { | |
120 return stackTrace.get(stackTrace.size()-1).call.text(); | |
121 } | |
93 } | 122 } |