From 2281d056ecf5f954dcc6f99a24fc90ce9f694757 Mon Sep 17 00:00:00 2001 From: Shu Lei Date: Wed, 7 Nov 2007 20:11:55 +0000 Subject: [PATCH] fix the scoping problem: variables in an outer scope were not included in the stack --- src/main/java/lua/debug/DebugStackState.java | 21 ++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/lua/debug/DebugStackState.java b/src/main/java/lua/debug/DebugStackState.java index e0297ede..1ce96a3a 100644 --- a/src/main/java/lua/debug/DebugStackState.java +++ b/src/main/java/lua/debug/DebugStackState.java @@ -477,8 +477,12 @@ public class DebugStackState extends StackState implements DebugRequestListener Vector variables = new Vector(); Hashtable variablesSeen = new Hashtable(); - addVariables(variables, variablesSeen, index); - + Proto p = calls[index].closure.p; + for (int i = index; i >= 0; i--) { + if (i == index || isInScope(p, calls[i])) { + addVariables(variables, variablesSeen, i); + } + } Variable[] result = new Variable[variables.size()]; for (int i = 0; i < variables.size(); i++) { result[i] = (Variable) variables.elementAt(i); @@ -487,6 +491,19 @@ public class DebugStackState extends StackState implements DebugRequestListener return result; } + protected boolean isInScope(Proto p, CallInfo ci) { + Proto[] enclosingProtos = ci.closure.p.p; + boolean bFound = false; + for (int i = 0; enclosingProtos!= null && i < enclosingProtos.length; i++) { + if (enclosingProtos[i] == p) { + bFound = true; + break; + } + } + + return bFound; + } + /** * Returns the visible globals to the current VM. * @return the visible globals.