Mercurial Hosting > luan
view src/luan/interp/UpValue.java @ 40:e3624b7cd603
implement stack trace
git-svn-id: https://luan-java.googlecode.com/svn/trunk@41 21e917c8-12df-6dd8-5cb6-c86387c605b9
author | fschmidt@gmail.com <fschmidt@gmail.com@21e917c8-12df-6dd8-5cb6-c86387c605b9> |
---|---|
date | Fri, 21 Dec 2012 10:45:54 +0000 |
parents | 0cdc1da466ee |
children | 64ecb7a3aad7 |
line wrap: on
line source
package luan.interp; final class UpValue { private Object[] stack; private int index; private boolean isClosed = false; private Object value; UpValue(Object[] stack,int index) { this.stack = stack; this.index = index; } UpValue(Object value) { this.value = value; this.isClosed = true; } Object get() { return isClosed ? value : stack[index]; } void set(Object value) { if( isClosed ) { this.value = value; } else { stack[index] = value; } } void close() { value = stack[index]; isClosed = true; stack = null; } static interface Getter { public UpValue get(LuaStateImpl lua); } static final class StackGetter implements Getter { private final int index; StackGetter(int index) { this.index = index; } public UpValue get(LuaStateImpl lua) { return lua.getUpValue(index); } } static final class NestedGetter implements Getter { private final int index; NestedGetter(int index) { this.index = index; } public UpValue get(LuaStateImpl lua) { return lua.closure().upValues[index]; } } static final Getter globalGetter = new Getter() { public UpValue get(LuaStateImpl lua) { return new UpValue(lua.global()); } }; }